Re: [R] How to repeat vectors ?

From: Adrian DUSA <adi_at_roda.ro>
Date: Sat 30 Sep 2006 - 11:48:54 GMT

Maybe this one?

> MyMatrix <- matrix(1:4, nrow=2)

> MyMatrix

     [,1] [,2]
[1,] 1 3
[2,] 2 4

> MyMatrix[rep(seq(nrow(MyMatrix)), each=2), ]

     [,1] [,2]

[1,]    1    3
[2,]    1    3
[3,]    2    4
[4,]    2    4


HTH,
Adrian

On Saturday 30 September 2006 09:33, Tong Wang wrote:
> I just figured out a way to do this:
> rep.vec <- function(X,n)
> return(t(array(rep(X,n),c(length(X),n))))
>
> Then, apply(MyMatrix, 2, rep.vec,2)
>
> Is there a better way ? Is there an internal function to repeat a vector
> or matrix ?
>
> Thanks a lot.
>
>
> ----- Original Message -----
> From: Tong Wang <wangtong@usc.edu>
> Date: Friday, September 29, 2006 11:23 pm
> Subject: How to repeat vectors ?
> To: r-help@stat.math.ethz.ch
>
> > Hi,
> > If I have a matrix , say a11 a12
> > a21 a22
> > Is there a routine to get: a11 a12
> > a11 a12
> > a21 a22
> > a21 a22
> >
> > Thanks a lot for any help.
> >
> > best

-- 
Adrian DUSA
Arhiva Romana de Date Sociale
Bd. Schitu Magureanu nr.1
050025 Bucuresti sectorul 5
Romania
Tel./Fax: +40 21 3126618 \
          +40 21 3120210 / int.101

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sat Sep 30 21:49:40 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 30 Sep 2006 - 12:30:07 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.