[R] Seeing negative numbers to zero
dwinsemius at comcast.net
Sat Aug 8 00:24:10 CEST 2009
On Aug 7, 2009, at 4:29 PM, DebbieMB wrote:
> 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
KN1 is probably still a dataframe (albeit with only one column) and
you really meant to be working on that column instead of the whole
dataframey-listy-thing with all of its attached attributes and
classes. You need to refer to the name of the column, let's say its
KN2 <- ifelse(KN1$col1<=0,0,KN1$col1)
> Any help would be appreciated.
> tonybreyal wrote:
>> see ?ifelse
>> you didn't specify what happens if a value is exactly zero in the
>> and so i've just bundled it in with the negative case:
>> x <- rnorm(20, 0, 1)
>> y<-ifelse(x<=0, 10, 5)
>> Tony Breyal
>> cmga20 wrote:
>>> Hi i am very new to R and I have been trying to change each
>>> piece of data in a data set to 10 if it is below 0 and 5 if it is
>>> 0. I know this sounds very easy but i am struggling!!
> View this message in context: http://www.nabble.com/For-loop-for-distinguishing-negative-numbers-tp24499872p24870518.html
> Sent from the R help mailing list archive at Nabble.com.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT
More information about the R-help