Re: [R] Matrix Construction; Subdiagonal

2009-03-13 Thread Paul Smith
On Wed, Mar 11, 2009 at 11:49 PM, Sundar Dorai-Raj 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 __ R-help@r-project.org ma

Re: [R] Matrix Construction; Subdiagonal

2009-03-11 Thread Stu Field
s.csiro.au/bill.venables/ > > > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org > ] On Behalf Of Sundar Dorai-Raj > Sent: Thursday, 12 March 2009 10:00 AM > To: Stu Field > Cc: r-help@r-project.org > Subject: Re: [R] Matr

Re: [R] Matrix Construction; Subdiagonal

2009-03-11 Thread Bill.Venables
f Of Sundar Dorai-Raj Sent: Thursday, 12 March 2009 10:00 AM To: Stu Field Cc: r-help@r-project.org Subject: Re: [R] Matrix Construction; Subdiagonal You can always write your own function: myDiag <- function(x, vec, k) { x[row(x) == col(x) - k] <- vec x } myDiag(A, vec, -1) Of course,

Re: [R] Matrix Construction; Subdiagonal

2009-03-11 Thread Bill.Venables
enables/ -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Stu Field Sent: Thursday, 12 March 2009 9:43 AM To: r-help@r-project.org Subject: [R] Matrix Construction; Subdiagonal I'm trying to enter a vector into the subdiagonal of a

Re: [R] Matrix Construction; Subdiagonal

2009-03-11 Thread Sundar Dorai-Raj
You can always write your own function: myDiag <- function(x, vec, k) { x[row(x) == col(x) - k] <- vec x } myDiag(A, vec, -1) Of course, you should probably do some input checking too. --sundar On Wed, Mar 11, 2009 at 4:57 PM, Stu Field wrote: > Sure, that'll work fine, thanks. > But I gu

Re: [R] Matrix Construction; Subdiagonal

2009-03-11 Thread Stu Field
Sure, that'll work fine, thanks. But I guess I was looking for something more similar to MatLab, I'm really surprised R doesn't have a preset command for this (?) Thanks again, Stu On 11 • Mar • 2009, at 5:49 PM, Sundar Dorai-Raj wrote: > > Does this help? > > A <- matrix(0, 6, 6) > vec <- 1:5

Re: [R] Matrix Construction; Subdiagonal

2009-03-11 Thread Sundar Dorai-Raj
Does this help? A <- matrix(0, 6, 6) vec <- 1:5 A[row(A) == col(A) + 1] <- vec --sundar On Wed, Mar 11, 2009 at 4:42 PM, Stu Field wrote: > I'm trying to enter a vector into the subdiagonal of a matrix but > cannot find a command in R which corresponds to the MatLab version of > diag(vec, k), w

[R] Matrix Construction; Subdiagonal

2009-03-11 Thread Stu Field
I'm trying to enter a vector into the subdiagonal of a matrix but cannot find a command in R which corresponds to the MatLab version of diag(vec, k), where vec = the vector of interest, and k = the diagonal (k=0 for the diagonal; k=-1 for the subdiagonal; k=1 for superdiagonal, etc.) Is the