[R] an easy way to construct this special matirx
De-Jian,ZHAO
zhaodj at ioz.ac.cn
Thu Aug 16 15:26:23 CEST 2007
Hi Gabor,
I am glad to see your answer,which gives a hope to resove this
question in an easy way. I replied to this question in a more
complex way before seeing your answer.
However,I think your code needs some revision, because the original
matrix is not a diagonal matrix. It has 4 rows and 5 columns.Looking
forward to your revised codes.
Best regards,
On Thu, Aug 16, 2007 20:22, Gabor Grothendieck wrote:
> Here are two solutions. In the first lo has TRUE on the lower
> diagonal
> and diagonal. Then we compute the exponents, multiplying by lo to
> zero
> out the upper triangle. In the second rn is a matrix of row numbers
> and rn >= t(rn) is the same as lo in the first solution.
>
> r <- 2; n <- 5 # test data
>
> lo <- lower.tri(diag(n), diag = TRUE)
> lo * r ^ (row(lo) - col(lo) + 1)
>
> Here is another one:
>
> rn <- row(diag(n))
> (rn >= t(rn)) * r ^ (rn - t(rn) + 1)
>
> On 8/15/07, shaowenhua at comcast.net <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
>
> ______________________________________________
> 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