[R] replace negative numbers by smallest positive value in matrix

2010-07-15 Thread Juliet Hannah
Hi Group, I have a matrix, and I would like to replace numbers less than 0 by the smallest minimum number. Below is an small matrix, and the loop I used. I would like to get suggestions on the R way to do this. Thanks, Juliet # example data set mymat - structure(c(-0.503183609420937,

Re: [R] replace negative numbers by smallest positive value in matrix

2010-07-15 Thread Jun Shen
Hi, Juliet, Something like this? mymat[mymat0]-min(mymat[mymat0]) Jun On Thu, Jul 15, 2010 at 10:55 AM, Juliet Hannah juliet.han...@gmail.com wrote: Hi Group, I have a matrix, and I would like to replace numbers less than 0 by the smallest minimum number. Below is an small matrix, and the

Re: [R] replace negative numbers by smallest positive value in matrix

2010-07-15 Thread Phil Spector
Juliet - Since you're operating on each column, apply() would be the appropriate function; mymat = apply(mymat,2,function(x){x[x0] = min(x[x0]);x}) - Phil Spector Statistical Computing Facility

Re: [R] replace negative numbers by smallest positive value in matrix

2010-07-15 Thread Juliet Hannah
Thanks Jun and Phil! On Thu, Jul 15, 2010 at 12:16 PM, Phil Spector spec...@stat.berkeley.edu wrote: Juliet -   Since you're operating on each column, apply() would be the appropriate function; mymat = apply(mymat,2,function(x){x[x0] = min(x[x0]);x})