Re: [R] Question on list object

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Wed, 27 Apr 2011 14:54:10 -0300

Try this:

sapply(listObj, '[', 1:max(sapply(listObj, length)))

On Wed, Apr 27, 2011 at 2:23 PM, Bogaso Christofer <bogaso.christofer_at_gmail.com> wrote:
> Dear all, let say, I have following list object:
>
>
>
> listObj <- vector("list", length = 3)
>
> listObj[[1]] <- rnorm(3)
>
> listObj[[2]] <- rnorm(4)
>
> listObj[[3]] <- rnorm(5)
>
>
>
> Now I want to convert above list into a Matrix. Ofcourse I can do it using
> "Reduce("rbind", listObj)". However as you notice that as elements of that
> list are arbitrary length vectors, I cant use this trick. What I want is to
> have a matrix with 3x5 dimension, where the remaining element of each row
> with be filled with NA, i.e I want :
>
>
>
> rbind(c(listObj[[1]], c(NA, NA)), c(listObj[[2]], c(NA)),listObj[[3]])
>
>
>
> Is there any better way on how I can do that more directly?
>
>
>
> Thanks and regards,
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Henrique Dallazuanna
Curitiba-Paran-Brasil
25 25' 40" S 49 16' 22" O

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 27 Apr 2011 - 18:08:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 27 Apr 2011 - 18:20:33 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive