[R] Rbind help needed
John Fox
jfox at mcmaster.ca
Wed Nov 27 21:29:43 CET 2002
At 01:23 PM 11/27/2002 -0500, Bayesianbay at aol.com wrote:
>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?
Dear Mick,
If efficiency isn't an issue, you could do
B <- A
for (i in 1:(n - 1)) B <- rbind(B, A)
A more efficient, but less transparent, approach would be
matrix(rep(t(A), n), nrow(A)*n, ncol(A), byrow=TRUE)
I hope that this helps,
John
____________________________
John Fox
Department of Sociology
McMaster University
email: jfox at mcmaster.ca
web: http://www.socsci.mcmaster.ca/jfox
____________________________
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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