[R] How to create an array of lists of multiple components?

Marius Hofert m_hofert at web.de
Wed Dec 29 21:25:09 CET 2010


how can I create an array of lists of three components?
This approach does not work:

n1 <- 2
n2 <- 4
n3 <- 5
res <- array(rep(vector("list",3), n1*n2*n3), dim = c(n1,n2,n3))
res[1,1,1] # is not a list with three components...

The goal is that res[1,1,1] is a list with three components. Also, appending the
components didn't work. For example, I tried:
component <- list(a = 4, b = "some text", c = 1)
for(i in 1:3) res[1,1,1] <- c(res[1,1,1], component[[i]])



More information about the R-help mailing list