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 wrote: > Juliet - >   Since you're operating on each column, apply() would > be the appropriate function; > > mymat = apply(mymat,2,function(x){x[x<0] = min(x[x>0]);x}) > > >                                        - Phil Spector

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[x<0] = min(x[x>0]);x}) - Phil Spector Statistical Computing Facility

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

2010-07-15 Thread Jun Shen
Hi, Juliet, Something like this? mymat[mymat<0]<-min(mymat[mymat>0]) Jun On Thu, Jul 15, 2010 at 10:55 AM, Juliet Hannah 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 loop I used. I

[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, 0.1790