Skip to content

Query: list within a list

3 messages · Stefano Sofia, Milan Bouchet-Valat, R. Michael Weylandt

#
Dear R users,
I have difficulty to create a list within a list.
Example: with
I create a list of 4 elements:
[[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.

Thank you for your attention and your help
Stefano Sofia PhD



AVVISO IMPORTANTE: Questo messaggio di posta elettronica pu? contenere informazioni confidenziali, pertanto ? destinato solo a persone autorizzate alla ricezione. I messaggi di posta elettronica per i client di Regione Marche possono contenere informazioni confidenziali e con privilegi legali. Se non si ? il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo messaggio. Se si ? ricevuto questo messaggio per errore, inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi dell?art. 6 della  DGR n. 1394/2008 si segnala che, in caso di necessit? ed urgenza, la risposta al presente messaggio di posta elettronica pu? essere visionata da persone estranee al destinatario.
IMPORTANT NOTICE: This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of Regione Marche may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system.
#
Le mercredi 22 f?vrier 2012 ? 16:17 +0100, Stefano Sofia a ?crit :
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
#
It's certainly possible and I don't think you get any grueling
inefficiencies. along the way.

Another way that might or might not make sense for you is to use a
nifty trick I saw Gabor and Duncan M use a few weeks ago: you can give
dimensionality to a list and then subset it in the "normal" ways:
e.g.,

x <- list(a = 1, b = 2, c = 3, d = 4)
dim(x) <- c(2,2)
colnames(x) <- c("a", "b")

x[2,]
x[,2]

x[[2]]]

x[,"a"]

Might be of help for some nifty indexing. (Or it might look so crazy
to scare folks away: your call)

Michael
On Wed, Feb 22, 2012 at 10:17 AM, Stefano Sofia
<stefano.sofia at regione.marche.it> wrote: