Re: Replicating Matricies...

Charles E. (cew@aris.ss.uci.edu)
Fri, 16 Jan 1998 16:29:49 -0800 (PST)


If you have a matrix mat with n rows, use
mat[rep(1:n, rep(2, n)),]

Ted Wright

On Fri, 16 Jan 1998, Chris Moyer wrote:

> Does anyone know how to replicate every other line in a matrix in
> Splus 4 without using a for() loop, e.g.,
>
> from:
>
> x1 x2 x3
> 1 1 10 15
> 2 2 11 16
> 3 3 12 17
> 4 4 13 18
> 5 5 14 19
> .
> .
> .
>
> to:
>
> x1 x2 x3
> 1 1 10 15
> 2 2 11 16
> 3 2 11 16
> 4 3 12 17
> 5 4 13 18
> 6 4 13 18
> 7 5 14 19
> .
> .
> .
>
> I know there must be a simple solution, but my novice skills are
> holding me back.
>
> Thanks for help in advance.
>
> Chris Moyer
>