[R] Query: list within a list

Milan Bouchet-Valat nalimilan at club.fr
Wed Feb 22 16:33:49 CET 2012


Le mercredi 22 février 2012 à 16:17 +0100, Stefano Sofia a écrit :
> Dear R users,
> I have difficulty to create a list within a list.
> Example: with
> 
> > A <- vector(mode="list", 4)
> 
> I create a list of 4 elements:
> > A
> [[1]]
> NULL
> 
> [[2]]
> NULL
> 
> [[3]]
> NULL
> 
> [[4]]
> NULL
> 
> In each element of this list I can store, for example, a matrix:
> A[[1]] <- matrix ...
> 
> I need each element of A to be a list (all the lists of the same
> length), and then store matrices within these lists.
> Have I explained it in a reasonable way?
> Is it possible?
> If yes, is it efficient? For my purposes, I need to have A a list of
> length 20000 or 30000 (even 50000 possibily), and the lists within A
> of length 1000 and store square matrices of dimension 13.
If all your matrices are of the same dimension, you can merge them into
arrays of dimensions 13x13x1000. Then, just put the arrays into a list.
Does that suit your needs?

(If you have enough RAM, you can even merge all the matrices into a big
array of dimensions 13x13x1000x50000, but...)


Regards



More information about the R-help mailing list