How to index elements in a list

Post date: Jun 30, 2013 8:06:58 PM

Here is some example:

> me<-list(name='Bot', age=18, info<-list(w=152, h=180, blood='O')) > me[2]; #output as list $age [1] 18 > me[[2]]; #output the element in the list [1] 18 > me[['age']]; #this can also be referenced by name [1] 18 > me['age']; #this is also possible, but output list $age [1] 18 > #---- Now let's see a list in a list ------- > me$info NULL > me[[3]] $w [1] 152 $h [1] 180 $blood [1] "O" > me[['info']] NULL > me<-list(name='Bot', age=18, info=list(w=152, h=180, blood='O')) > me$info $w [1] 152 $h [1] 180 $blood [1] "O" > # So, to define name in a list, we use '=' and not '<-'!!! > me[['info']] $w [1] 152 $h [1] 180 $blood [1] "O" > me[['info']]$w [1] 152 > me[['info']][['w']] [1] 152 > me[['info']]['w'] $w [1] 152 > me[['info']]$blood [1] "O" >