[R] replicate matrix

Dimitris Rizopoulos d.rizopoulos at erasmusmc.nl
Sun Feb 21 07:13:34 CET 2010


try this:

mat <- matrix(c(1,4,3,6), 2, 2)

cbind(
     do.call(cbind, rep(list(mat), 3)),
     c(2, 5)
)


I hope it helps.

Best,
Dimitris


wendy wrote:
> Hi all,
> 
> I have a matrix, for example
>      [,1] [,2]
> [1,]  1    3
> [2,]  4    6
> 
> I want to replicate the matrix twice and add an extra column at the end,
> which is
>      [,1] [,2] [,3] [,4] [,5] [,6] [,7]
> [1,]  1    3     1    3     1    3    2
> [2,]  4    6     4    6     4    6    5
> 
> I found 'rep' only works for vector. Does anyone know how to replicate a
> matrix, and append the matrix?
> 
> Thank you in advance,
> Wendy  
> 
> 

-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014



More information about the R-help mailing list