[R] Question: concatenating lists

Putter, H. (MStat) H.Putter at lumc.nl
Mon Oct 14 17:03:40 CEST 2002


Dear R users,

I have the following problem. I have a number of lists with identical
structure. Each component is a vector, matrix or array, but components of
different lists may be of different size. How do I combine the lists to get
a new list such that each component of this list contains the components of
the individual lists?

An example may explain most clearly what I need.

Suppose I have three lists:
list1 <- list(a=1:2,b=matrix(1,2,2))
list2 <- list(a=3:5,b=matrix(-1,3,3))
list3 <- list(a=6:9,b=matrix(5,4,4))

The result should give me something like:

$a:
     [,1] [,2] [,3] 
[1,]    1    3    6
[2,]    2    4    7
[3,]   NA    5    8
[4,]   NA   NA    9


$b:
, , 1
     [,1] [,2] [,3] [,4] 
[1,]    1    1   NA   NA
[2,]    1    1   NA   NA
[3,]   NA   NA   NA   NA
[4,]   NA   NA   NA   NA

, , 2
     [,1] [,2] [,3] [,4] 
[1,]   -1   -1   -1   NA
[2,]   -1   -1   -1   NA
[3,]   -1   -1   -1   NA
[4,]   NA   NA   NA   NA

, , 3
     [,1] [,2] [,3] [,4] 
[1,]    5    5    5    5
[2,]    5    5    5    5
[3,]    5    5    5    5
[4,]    5    5    5    5

Any ideas would be much appreciated.
Best regards,
	Hein


Hein Putter
Department of Medical Statistics
Leiden University Medical Center
P.O.Box 9604,  
2300 RC Leiden, The Netherlands
phone  +31-71-5276827
fax    +31-71-5276799
e-mail h.putter at lumc.nl
http://www.medstat.medfac.leidenuniv.nl/MS/Hp



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list