[R] Matrix Construction; Subdiagonal

Paul Smith phhs80 at gmail.com
Fri Mar 13 19:05:37 CET 2009


On Wed, Mar 11, 2009 at 11:49 PM, Sundar Dorai-Raj <sdorairaj at gmail.com> wrote:
> Does this help?
>
> A <- matrix(0, 6, 6)
> vec <- 1:5
> A[row(A) == col(A) + 1] <- vec

Maybe, more simply:

A <- matrix(0, 6, 6)
vec <- 1:5
diag(A[-1,]) <- vec

Paul




More information about the R-help mailing list