r - Lists with multiple 'nested' items -
really basic question can't find answer - i've misunderstood lists in r
can have multiple 'nested' items held in list? fine:
cats<-c("red", "blue", "yellow") l1<-list() for(i in cats){ l1[i][1]<-"hello" };l1
this not:
for(i in cats){ l1[i][2]<-"goodbye" };l1
the output have in mind mean
l1$red[1]
"hello"
, l1$red[2]
"goodbye"
am setting list incorrectly? or entire concept flawed?
thanks
you have access list elements [[
instead of [
:
for(i in cats){ l1[[i]][1]<-"hello" };l1 for(i in cats){ l1[[i]][2]<-"goodbye" };l1 > l1$red[1] [1] "hello" > l1$red[2] [1] "goodbye"
see this post how access list elements.
Comments
Post a Comment