[R] cbind a list of matrices

S.O. Nyangoma S.O.Nyangoma at amc.uva.nl
Sat Jul 16 15:50:10 CEST 2005


> Didn't you simply try:
> 
> > A<-matrix(c(1.1,1.2,1.3,1.4,1.5,1.6),ncol=3)
> > B<-matrix(c(2.1,2.2,2.3,2.4,2.5,2.6),ncol=3)
> > C<-matrix(c(3.1,3.2,3.3,3.4,3.5,3.6),ncol=3)
> > A
>     [,1] [,2] [,3]
> [1,]  1.1  1.3  1.5
> [2,]  1.2  1.4  1.6
> > B
>     [,1] [,2] [,3]
> [1,]  2.1  2.3  2.5
> [2,]  2.2  2.4  2.6
> > C
>     [,1] [,2] [,3]
> [1,]  3.1  3.3  3.5
> [2,]  3.2  3.4  3.6
> > rbind(A,B,C)
>     [,1] [,2] [,3]
> [1,]  1.1  1.3  1.5
> [2,]  1.2  1.4  1.6
> [3,]  2.1  2.3  2.5
> [4,]  2.2  2.4  2.6
> [5,]  3.1  3.3  3.5
> [6,]  3.2  3.4  3.6
> > rbind(A,A,A)
>     [,1] [,2] [,3]
> [1,]  1.1  1.3  1.5
> [2,]  1.2  1.4  1.6
> [3,]  1.1  1.3  1.5
> [4,]  1.2  1.4  1.6
> [5,]  1.1  1.3  1.5
> [6,]  1.2  1.4  1.6
> 


This would be adequate for low dimensional dataset e.g. the example 
you have give. What if you have a list of thousands of matrices. Is 
there an efficient way of doing this other than looping?




More information about the R-help mailing list