Skip to content
Back to formatted view

Raw Message

Message-ID: <536CC57C.60405@gmail.com>
Date: 2014-05-09T12:09:32Z
From: Jean-Daniel Sylvain
Subject: Repeat columns and rows of matrix
In-Reply-To: <1399635217003-7586408.post@n2.nabble.com>

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