Re: [R] re placing values in a matrix

2008-02-01 Thread Gabor Csardi
Derek, the 0*m part zeros out everything in the matrix, expect for the NA's, 0*NA=NA by definition. If we add this to the y[ col(m) ] matrix, then NA+anything=NA, but 0+anything=anything. G. ps. please answer to the list (as well) On Fri, Feb 01, 2008 at 08:52:50AM -0500, Derek Cyr wrote: >

Re: [R] re placing values in a matrix

2008-02-01 Thread Gabor Csardi
Actually, you don't need apply. If there are no NA's then it is very easy: m[] <- y[ col(m) ] If you want to keep the NA's then it is a bit more tricky: m[] <- 0*m + y[ col(m) ] G. On Thu, Jan 31, 2008 at 07:03:51PM -0800, dxc13 wrote: > > useR's, > > Consider: > y <- c(20, 25, 30) > > m <

[R] re placing values in a matrix

2008-02-01 Thread dxc13
useR's, Consider: y <- c(20, 25, 30) > m <- matrix(c(0.0,1,NA,0.5,1.25,0.75, 0.5, NA, > NA),byrow=TRUE,nrow=3,ncol=3) > m [,1] [,2] [,3] [1,] 0.0 1.00 NA [2,] 0.5 1.25 0.75 [3,] 0.5 NA NA For each numeric value, I want to replace them with their corresponding y-value. The result s