[R-sig-Geo] Repeat columns and rows of matrix
Roger Bivand
Roger.Bivand at nhh.no
Fri May 9 14:59:47 CEST 2014
If this question is related to an earlier one (LM tests for spatial panel
data), I don't think that the correct expansion of W for T=2 is:
W W
W W
but rather
W 0
0 W
so a Kronecker product of W and diag(T). Here the output is sparse, and
with T=9 and N=1K, this may be important, especially if W is sparse too.
However, we don't know. So for now we need
M <- matrix(1, nrow=9, ncol=9)
W9 <- kronecker(W, M)
which answers the apparent question. However, I don't think that it was
the intention.
Roger
On Fri, 9 May 2014, Jean-Daniel Sylvain wrote:
> 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
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list