[R] efficient list indexing

Patrick Burns pburns at pburns.seanet.com
Wed Sep 22 12:57:28 CEST 2010


I'm confused by what you are looking for.
There's some slight possibility that you
are looking for double bracket subscripting
with a vector:

 > list(a=1:5, b=letters)[[c(2,4)]]
[1] "d"


On 22/09/2010 10:58, Alaios wrote:
> Hello everyone,
>
> I need some help with lists inside lists (a good way to emulate a struct)\
>
> Assume that there is a small list called fred:
> fred<- list(happy = 1:10, name = "squash")
>
>
> and a big list called bigfred that includes fred list 5 times
> bigfred<- rep(fred,5)
>
> Is it possible somehow to index all these sublists(fred) inside bigfred with a
> more direct way like this:
> bigfred[1] shows the first sublist fred
> bigfred[2][2] shows the second sublist fred, the second element of the fred list
>
> So far I found some way to do this by refering to the sublists by the following:
> bigfred[1+index*length(fred)]
> where index shows the beginning of a sublist.
>
> I would like to thank you in advance for your help
> Best Regards
> Alex
>
>
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Patrick Burns
pburns at pburns.seanet.com
http://www.burns-stat.com
(home of 'Some hints for the R beginner'
and 'The R Inferno')



More information about the R-help mailing list