[R-sig-Geo] Repeat columns and rows of matrix

Jean-Daniel Sylvain jeandaniel.sylvain at gmail.com
Fri May 9 14:09:32 CEST 2014


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 :
> Dear list,
> i have a matrixW(1060*1060), i want to repeat each column and row 9 times,
> such as to have a new matrix W1(9540*9540).
> I use the code:
> rep.row<-function(x,n){
>     matrix(rep(x,each=n),nrow=n)
> }
> rep.col<-function(x,n){
>     matrix(rep(x,each=n), ncol=n, byrow=TRUE)
> }
>
> ww<-rep.row(w,9)
> W1<-rep.col(ww,9)
>
> but i did not work!
>
> Is there another way to do it ?
>
> Any help would me appreciated.
> Thank YOU.
>
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Repeat-columns-and-rows-of-matrix-tp7586408.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list