Message-ID: <20020321132110.GD32235@giraffa.cbs.dtu.dk>
Date: 2002-03-21T13:21:10Z
From: Laurent Gautier
Subject: repeating rows or columns within a matrix
In-Reply-To: <3C99B3B9.29D2FD61@labour.fi>
On Thu, Mar 21, 2002 at 12:19:37PM +0200, 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?
>
> Many thanks
>
> Juhana Vartiainen
> juhana.vartiainen at 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 at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I do not know if it is a smart way, but that's a way:
m <- matrix(1:9, 3, 3, byrow=T)
rep.fact <- 2 # repeating factor, say 2
mm <- matrix(rep(m, rep(rep.fact, length(m))), nrow(m)*rep.fact, ncol(m))
Hopin' it helps,
Laurent
--
--------------------------------------------------------------
Laurent Gautier CBS, Building 208, DTU
PhD. Student D-2800 Lyngby,Denmark
tel: +45 45 25 24 85 http://www.cbs.dtu.dk/laurent
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._