[R] an easy way to construct this special matirx
De-Jian,ZHAO
zhaodj at ioz.ac.cn
Thu Aug 16 14:25:32 CEST 2007
Hi wen,
I don't think it is easy to construct this matrix in a simple way. I
tried and found a way to do it. Try the following codes:
i<-1:4
j<-5
aa<-matrix(0,4,5)
for (j in 1:5){aa[i,j]<-(i+1-j)}
r<-4 #r could be any number
bb<-r^aa
bb[aa<0]=0
bb
The matrix bb is what you want. Furthermore,I packaged this process
into a function called mtrx as below:
mtrx<-function(row,clm,r){
i<-1:row
j<-clm
aa<-matrix(row*clm,row,clm)
for (j in 1:clm){aa[i,j]<-(i+1-j)}
#r could be any number
bb<-r^aa
bb[aa<0]=0
bb
}
Now you can use the function to produce the matrix.The
above-mentioned matrix is mtrx(4,5,4)
Dejian Zhao
On Thu, Aug 16, 2007 11:10, shaowenhua at comcast.net wrote:
> Hi,
> Sorry if this is a repost. I searched but found no results.
> I am wondering if it is an easy way to construct the following
> matrix:
>
> r 1 0 0 0
> r^2 r 1 0 0
> r^3 r^2 r 1 0
> r^4 r^3 r^2 r 1
>
> where r could be any number. Thanks.
> Wen
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
De-Jian Zhao
Institute of Zoology,Chinese Academy of Sciences
+86-10-64807217
zhaodj at ioz.ac.cn
More information about the R-help
mailing list