[R] repeating rows or columns within a matrix

Dr. Diego Kuonen kuonen at statoo.com
Thu Mar 21 11:48:20 CET 2002


Juhana Vartiainen wrote:
> 
> Spse I have a matrix, say
...
> and I would like to expand it by repeating rows within the matrix, to
> get, if the repeating factor is 2, say:
... 
> (or columnwise as well) . There must be a smart way of doing that?

For your particular example the following works

  apply(matrix(1:9,ncol=3,byrow=T), 2, rep, rep(2,3))

You may also want to look at 

  ?apply
  ?rep

to adapt it to your needs.

Sincerely,

  Diego Kuonen

  
-- 
Dr. ès sc. Diego Kuonen        CEO & Applied Statistician 
Statoo Consulting, PO Box 107, 1015 Lausanne, Switzerland
+ Have you ever been Statooed?   http://www.statoo.info +
+ Free Statooed newsletters:    http://lists.statoo.com +
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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