Assignment in R language

后端 未结 3 2017
刺人心
刺人心 2021-02-19 09:54

I am wondering how assignment works in the R language.

Consider the following R shell session:

> x <- c(5, 6, 7)
> x[1] <- 10
> x
[1] 10 6         


        
3条回答
  •  被撕碎了的回忆
    2021-02-19 10:43

    It seems to me that one can only assign values to named data structures (like 'x').

    That's precisely what the documentation for ?"<-" says:

    Description:

     Assign a value to a name.
    

    x[1] <- 10 doesn't use the same function as x <- c(5, 6, 7). The former calls [<- while the latter calls <-.

提交回复
热议问题