[R] rbind a list of matrices
Berend Hasselman
bhh at xs4all.nl
Thu Mar 7 19:28:53 CET 2013
On 07-03-2013, at 17:52, Heath Blackmon <coleoguy at gmail.com> wrote:
> I have a large list of matrices and a vector that identifies the desired
> matrices that I would like to rbind. However, I am stuck on how to get
> this to work. I have written some code below to illustrate my problem:
>
> # 3 simple matrices
> a<-matrix(1:9,3,3)
> b<-matrix(10:18,3,3)
> c<-matrix(19:27,3,3)
>
> #this is the type of list of matrices I am dealing with
> matrix.list<-vector("list",3)
> matrix.list[[1]]<-a
> matrix.list[[2]]<-b
> matrix.list[[3]]<-c
>
> #i have a vector that identifies the ones that i want
> desired.matrices <- c(1,3)
>
> #i have tried lots of things next but all fail. This one gets close but I
> seem to lose my dim attributes
> goal<-rbind(matrix.list[desired.matrices])
>
> Any ideas would be wonderful.
do.call(rbind,matrix.list)
Berend
More information about the R-help
mailing list