Re: [R] save a list as a matrix

2010-11-20 Thread Henrique Dallazuanna
Try this also: t(sapply(my.list, '[', seq(max(sapply(my.list, length) On Sat, Nov 20, 2010 at 9:06 AM, Robert Ruser wrote: > Hello, > Let's assume that one has a list: > my.list <- list(a=c(1,2,3,4),b=4,c=c(1:7)) > > I want to save my.list as a matrix in .txt file. Because of different > le

Re: [R] save a list as a matrix

2010-11-20 Thread Robert Ruser
Hi Mohamed, It works. Thank you very much. Best, Robert 2010/11/20 : > Hi Robert, > > Try to do this > >  Len <- max(sapply(my.list, length)) > >  fun1 <- lapply(my.list, function(x){ >      c(x, rep(0, Len))[1:Len] >  }) >  do.call(rbind, fun1) > > M > Regards

[R] save a list as a matrix

2010-11-20 Thread Robert Ruser
Hello, Let's assume that one has a list: my.list <- list(a=c(1,2,3,4),b=4,c=c(1:7)) I want to save my.list as a matrix in .txt file. Because of different length we can put NA or 0. Effect (row.names a, b and c are not necessary) a 1 2 3 4 0 0 0 b 4 0 0 0 0 0 0 c 1 2 3 4 5 6 7 How to do it? Than