Skip to content
Prev 18137 / 398502 Next

repeating rows or columns within a matrix

Juhana Vartiainen wrote:
You could do something like that:

R> mymatrix <- matrix(1:9, ncol=3)
R> myindex <- rep(1:nrow(mymatrix), rep(2, nrow(mymatrix)))
R> mymatrix[myindex,]
     [,1] [,2] [,3]
[1,]    1    4    7
[2,]    1    4    7
[3,]    2    5    8
[4,]    2    5    8
[5,]    3    6    9
[6,]    3    6    9

Best,
Z
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._