Filip - 11 months ago 67

R Question

I have stumbled apon this code:

`colnames(dataFrame) <- c("firstCol", "secondCol")`

which renames columns of given dataframe dataFrame. What is happening there? How can I possibly assign something to return value?

Corresponding R-fiddle

Answer Source

Example 1:

```
> `setvalue<-` <- function(x,value) value
> x <- 0
> setvalue(x) <- 1
> x
[1] 1
```

Example 2:

```
> `add<-` <- function(x,value) x+value
> x
[1] 1
> add(x) <- 3 # x <- x+3
> x
[1] 4
```