0

I have a question on the difference between the double brackets and the dollar sign in R. Let's take the following as an example.

x <- list(foo=1:4, bar=1)

colName <- "foo"
x[[colName]]
[1] 1 2 3 4

x$colName
NULL

It's a little bit odd to me. If I use the double brackets, I can get the values. But if I use the $, I can't get it. Why? Could someone help me?

wh41e
  • 183
  • 1
  • 3
  • 10

0 Answers0