0

I saw this as a question on datacamp.

(1)

vector <- c("a","b","c","d")
my_list <- list(vec=vector)
my_list

output:

$vec [1]"a" "b" "c" "d"

(2)

vector <- c("a","b","c","d")
my_list <- list(vec<-vector)
my_list

output:

[[1]]
[1] "a" "b" "c" "d"

So, I wondered how different they are and what's the different between <- and = in R. I would highly appreciate any help.

  • https://stat.ethz.ch/R-manual/R-patched/library/base/html/assignOps.html – cgvoller Feb 06 '22 at 20:16
  • When you type `list(vec<-vector)` the interior of the call to list is evaluated and then the result which is an unnamed vector with the value of `vector`. The name "vec" is basically discarded. – IRTFM Feb 06 '22 at 20:39
  • Consider what you get with `matrix(1, ncol <- 2)`. It is probably not what you would expect. – IRTFM Feb 06 '22 at 20:47

0 Answers0