[R] Seeing negative numbers to zero
djnordlund at verizon.net
Fri Aug 7 23:50:08 CEST 2009
> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of DebbieMB
> Sent: Friday, August 07, 2009 1:29 PM
> To: r-help at r-project.org
> Subject: [R] Seeing negative numbers to zero
> I am also new to R and I have a related question. I am trying to set
> negative values in a single column of a dataframe to zero and
> I can't seem
> to do it.
> I have tried:
> # Here I am selecting the column of the dataframe KN1 and
> assigning it the
> name KN2 - this step works
> # Here I am trying to set negative numbers to zero and leave all other
> numbers the same - this doesn't work
> Any help would be appreciated.
When you say it doesn't work, what does that mean? Do you get an error
message? Are you left with negative numbers? What? A minimal,
self-contained, reproducible example would help us help you.
> KN1 <- rnorm(100)
> KN2 <- ifelse(KN1 < 0, 0, KN1)
Works fine for fine for me.
Bothell, WA USA
More information about the R-help