What is difference between double bracket and $ in R

r

#1

I have created a variable which stores a variable name of list but when I have used the double bracket it works but while I have used a dollar sign it not works

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

names<-'foo’
x[[names]]
[1] 1 2 3 4
x$names
NULL


#2

Please see below:

To change the name you have to use names(obj)[i th element].
Note:Ignore the error message.
Hope this helps!!