[R] Rbind help needed

Tony Plate tplate at blackmesacapital.com
Wed Nov 27 21:10:42 CET 2002


At 01:23 PM 11/27/2002 -0500, Bayesianbay at aol.com wrote:
>Dear list
>
>I have a very simple question which is causing me problems!
>
>I have a matrix A and simply want to rbind this matrix together n times (n 
>is a large number)
>How can I write this in R?
>I know I could do new<-rbind(z,z,z,...z) with z written n times but this 
>will take forever as n is so large.
>
>Is there a simple way to write this?

An easy way is to not use rbind, but to use row-indexing, e.g.:

 > x <- matrix(1:4, ncol=2)
 > x
      [,1] [,2]
[1,]    1    3
[2,]    2    4
 > rep(seq(len=nrow(x)),3)
[1] 1 2 1 2 1 2
 > x[rep(seq(len=nrow(x)),3),]
      [,1] [,2]
[1,]    1    3
[2,]    2    4
[3,]    1    3
[4,]    2    4
[5,]    1    3
[6,]    2    4
 >

-- Tony Plate

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list