From: Achim Zeileis (zeileis@ci.tuwien.ac.at)
Date: Thu 21 Mar 2002 - 21:45:16 EST
Message-id: <3C99B9BC.7DF7C0F6@ci.tuwien.ac.at>
Juhana Vartiainen wrote:
>
> Hello
>
> Spse I have a matrix, say
>
> 1 2 3
> 4 5 6
> 7 8 9
>
> and I would like to expand it by repeating rows within the matrix, to
> get, if the repeating factor is 2, say:
>
> 123
> 123
> 456
> 456
> 789
> 789
>
> (or columnwise as well) . There must be a smart way of doing that?
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
> Many thanks
>
> Juhana Vartiainen
> juhana.vartiainen@labour.fi
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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@stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
This archive was generated by hypermail 2.1.3 : Wed 16 Oct 2002 - 11:57:05 EST