Skip to content
Prev 20993 / 29559 Next

Repeat columns and rows of matrix

Hi,

You hould use the apply function function, which will apply the function 
rep() on one of the dimension of your matrix (1 for row, and 2 for columns).

mat <- matrix(data=1:100,10,10)

apply(mat,MARGIN=1,function(x) rep(x,10))
apply(mat,MARGIN=2,function(x) rep(x,10))

Hope this helps,

JD

Le 5/9/2014 7:33 AM, az14 a ?crit :