Skip to content

Convert a list to matrix

3 messages · Daren Tan, jim holtman, Dimitris Rizopoulos

#
This should do what you want:
+     c(.ele, rep(NA, maxLen))[1:maxLen]
+ })
[,1] [,2]
A    1   NA
B    2    3

        
On Sat, Feb 21, 2009 at 10:17 PM, Daren Tan <darentan76 at gmail.com> wrote:

  
    
#
one way is the following:

m <- list(A = 1, B = 1:2, C = 1:3, D = 1:4)

n <- max(sapply(m, length))
t(sapply(m, function (x) c(x, rep(NA, n - length(x)))))


I hope it helps.

Best,
Dimitris
Daren Tan wrote: