[R] repeating rows or columns within a matrix
Andreas Kiermeier
Andreas.Kiermeier at adelaide.edu.au
Thu Mar 21 23:30:57 CET 2002
>>>>> "Juhana" == Juhana Vartiainen <juhana.vartiainen at labour.fi> writes:
Juhana> Hello
Juhana> Spse I have a matrix, say
Juhana> 1 2 3
Juhana> 4 5 6
Juhana> 7 8 9
Juhana> and I would like to expand it by repeating rows within the matrix, to
Juhana> get, if the repeating factor is 2, say:
Juhana> 123
Juhana> 123
Juhana> 456
Juhana> 456
Juhana> 789
Juhana> 789
Juhana> (or columnwise as well) . There must be a smart way of doing that?
Juhana,
you could try the kronecker product
> z <- matrix(1:9,ncol=3,byrow=T)
> z
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 7 8 9
> kronecker(z, c(1,1))
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 1 2 3
[3,] 4 5 6
[4,] 4 5 6
[5,] 7 8 9
[6,] 7 8 9
Cheers,
Andreas
--
Andreas Kiermeier
Senior Biometrician
BiometricsSA (Adelaide University/SARDI)
GPO Box 397, Adelaide, SA 5001, Australia
Email: Andreas.Kiermeier at adelaide.edu.au
WWW: http://www.BiometricsSA.adelaide.edu.au/
Ph: +61 8 8303 6819
Fax: +61 8 8303 6761
-----------------------------------------------------------
This email message is intended only for the addressee(s)
and contains information which may be confidential and/or
copyright. If you are not the intended recipient please
do not read, save, forward, disclose, or copy the contents
of this email. If this email has been sent to you in error,
please notify the sender by reply email and delete this
email and any copies or links to this email completely and
immediately from your system. No representation is made
that this email is free of viruses. Virus scanning is
recommended and is the responsibility of the recipient.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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