Skip to content

Change negative values in column

2 messages · Joel Fürstenberg-Hägg, Steve Lianoglou

#
Hi,
On Nov 3, 2009, at 9:56 AM, Joel F?rstenberg-H?gg wrote:

            
This is telling you that x[i] is a zero length object, so you're  
indexing is wrong
You have to tell R to only use positive numbers, min(x[x > 0]) would  
have worked.

I'm not really sure what you're looping over below.
This will work over each column of an "orig.df" data.frame (assumes  
all cols are numeric) and generate the new data.frame you're looking  
for:

new.df <- as.data.frame(apply(orig.df, 2, function(col) {
   min.val <- min(col[col > 0])
   col[col < 0] <- min.val
   col
}))

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
   |  Memorial Sloan-Kettering Cancer Center
   |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact