Re: [R] Convert "ragged" list to matrix

2009-06-22 Thread Gabor Grothendieck
Try this: > unname(t(do.call(cbind, lapply(a, ts [,1] [,2] [,3] [,4] [1,] "a" "b" "c" NA [2,] "d" "e" NA NA [3,] "f" "g" "h" "i" On Mon, Jun 22, 2009 at 7:15 PM, Kenneth Takagi wrote: > Hi, > > > > I have a list made up of character strings with each item a different > length

Re: [R] Convert "ragged" list to matrix

2009-06-22 Thread Kenneth Takagi
: Monday, June 22, 2009 7:24 PM To: Kenneth Takagi Cc: r-help@r-project.org Subject: Re: [R] Convert "ragged" list to matrix try this: > a [[1]] [1] "a" "b" "c" [[2]] [1] "d" "e" [[3]] [1] "f" "g" "h" &q

Re: [R] Convert "ragged" list to matrix

2009-06-22 Thread Henrique Dallazuanna
Try this: matrix(unlist(lapply(a, '[', 1:max(sapply(a, length, ncol = 4, byrow = TRUE) or do.call(rbind, lapply(a, '[', 1:max(sapply(a, length On Mon, Jun 22, 2009 at 8:15 PM, Kenneth Takagi wrote: > Hi, > > > > I have a list made up of character strings with each item a different >

Re: [R] Convert "ragged" list to matrix

2009-06-22 Thread jim holtman
try this: > a [[1]] [1] "a" "b" "c" [[2]] [1] "d" "e" [[3]] [1] "f" "g" "h" "i" > # find max row length > rowMax <- max(sapply(a, length)) > # now create output matrix by lengthening rows > do.call(rbind, lapply(a, function(x){ + length(x) <- rowMax + x + })) [,1] [,2] [,3] [,4] [1,]

[R] Convert "ragged" list to matrix

2009-06-22 Thread Kenneth Takagi
Hi, I have a list made up of character strings with each item a different length (each item is between 1and 6 strings long). Is there a way to convert a "ragged" list to a matrix such that each item is its own row? Here is a simple example: a=list(); a[[1]] = c("a", "b", "c"); a[[2]] = c