[R] extracting a subset of sublists form a list; vectorized form

jgarcia at ija.csic.es jgarcia at ija.csic.es
Wed Oct 8 18:38:01 CEST 2008


Hello;
I'll put my real problem through a simple example:
I've got a main list:

> main.lst <- lst()

With a number of sublists:

> for(i in 1:1000){
   main.lst[[i]] <- list()
   main.lst[[i]]$first  <- runif(1,0,1)
   main.lst[[i]]$second <- runif(2,3,4)
  }

If later on I need to split this list, how could I extract several
sublists in a vectorized form? For example, to extract the four first
sublists, to be passed to a function, sintaxis like this won't work:

> sublist <- main.lst[[1:4]]

Although I could do

> sublist <- list()
> for(i in 1:4){ sublist[[i]] <- main.lst[[i]] }

I would hope that a vectorized way could exist.

Thanks, and regards,
Javier
-------



More information about the R-help mailing list