> -----Original Message----- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of DebbieMB > Sent: Friday, August 07, 2009 1:29 PM > To: r-help@r-project.org > Subject: [R] Seeing negative numbers to zero > > > Hi, > > 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: > KN1<-subset(KN,select=c(5)) > # Here I am selecting the column of the dataframe KN1 and > assigning it the > name KN2 - this step works > KN2<-ifelse(KN1<=0,0,KN1) > # 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. > > Thanks, > Debbie
Debbie, 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. Dan Daniel Nordlund Bothell, WA USA ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.