Re: [R] how ot replace the diagonal of a matrix

2006-10-03 Thread Peter Dalgaard
Duncan Murdoch <[EMAIL PROTECTED]> writes: > On 10/3/2006 4:59 PM, roger bos wrote: > > Dear useRs, > > > > Trying to replace the diagonal of a matrix is not working for me. I > > want a matrix with .6 on the diag and .4 elsewhere. The following > > code looks like it should work--when I lookk

Re: [R] how ot replace the diagonal of a matrix

2006-10-03 Thread Deepayan Sarkar
On 10/3/06, roger bos <[EMAIL PROTECTED]> wrote: > Dear useRs, > > Trying to replace the diagonal of a matrix is not working for me. I > want a matrix with .6 on the diag and .4 elsewhere. The following > code looks like it should work--when I lookk at mps and idx they look > how I want them too-

Re: [R] how ot replace the diagonal of a matrix

2006-10-03 Thread Charles C. Berry
On Tue, 3 Oct 2006, Duncan Murdoch wrote: > On 10/3/2006 4:59 PM, roger bos wrote: >> Dear useRs, >> >> Trying to replace the diagonal of a matrix is not working for me. I >> want a matrix with .6 on the diag and .4 elsewhere. The following >> code looks like it should work--when I lookk at mps

Re: [R] how ot replace the diagonal of a matrix

2006-10-03 Thread Marc Schwartz (via MN)
On Tue, 2006-10-03 at 17:03 -0400, Duncan Murdoch wrote: > On 10/3/2006 4:59 PM, roger bos wrote: > > Dear useRs, > > > > Trying to replace the diagonal of a matrix is not working for me. I > > want a matrix with .6 on the diag and .4 elsewhere. The following > > code looks like it should work--

Re: [R] how ot replace the diagonal of a matrix

2006-10-03 Thread jim holtman
try: > mps <- matrix(rep(.4, 3*3), nrow=3, byrow=TRUE) > idx <- diag(3) > mps [,1] [,2] [,3] [1,] 0.4 0.4 0.4 [2,] 0.4 0.4 0.4 [3,] 0.4 0.4 0.4 > idx [,1] [,2] [,3] [1,]100 [2,]010 [3,]001 > mps[idx == 1] <- rep(.6,3) > > mps [,1] [,2] [,

Re: [R] how ot replace the diagonal of a matrix

2006-10-03 Thread Tony Plate
You are indexing with numeric 0's and 1's, which will refer to only the matrix element 1,1 (multiple times), cf: > matrix(1:9,3)[diag(3)] [1] 1 1 1 > Try one of these: > idx <- diag(3) > 0 > idx <- which(diag(3)>0) > idx <- cbind(seq(len=n), seq(len=n)) (For very large matrices, the third

Re: [R] how ot replace the diagonal of a matrix

2006-10-03 Thread Duncan Murdoch
On 10/3/2006 4:59 PM, roger bos wrote: > Dear useRs, > > Trying to replace the diagonal of a matrix is not working for me. I > want a matrix with .6 on the diag and .4 elsewhere. The following > code looks like it should work--when I lookk at mps and idx they look > how I want them too--but it o

[R] how ot replace the diagonal of a matrix

2006-10-03 Thread roger bos
Dear useRs, Trying to replace the diagonal of a matrix is not working for me. I want a matrix with .6 on the diag and .4 elsewhere. The following code looks like it should work--when I lookk at mps and idx they look how I want them too--but it only replaces the first element, not each element on