Dear all, I'm trying to replace NA values with -9999 in one column of a data frame. I've tried using is.na and the testdata[testdata$onecolumn==NA] <- 9999 approach, but whilst neither generate errors, neither result in -9999s appearing - the NAs remain there! I'd be grateful for any advice on what I'm doing wrong or any other suitable approaches. Many thanks, Steve _________________________________________________________________ oticons.
testdata[is.na(testdata$onecolumn)] <- -9999 On Mon, Aug 17, 2009 at 11:41 AM, Steve Murray<smurray444 at hotmail.com> wrote:> > Dear all, > > I'm trying to replace NA values with -9999 in one column of a data frame. I've tried using is.na and the testdata[testdata$onecolumn==NA] <- 9999 approach, but whilst neither generate errors, neither result in -9999s appearing - the NAs remain there! > > I'd be grateful for any advice on what I'm doing wrong or any other suitable approaches. > > Many thanks, > > Steve > > _________________________________________________________________ > > oticons. > > ______________________________________________ > R-help at 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Petr PIKAL
2009-Aug-18 12:43 UTC
[R] Odp: Replacing NA values in one column of a data.frame
Hi r-help-bounces at r-project.org napsal dne 17.08.2009 17:41:59:> > Dear all, > > I'm trying to replace NA values with -9999 in one column of a dataframe. I've Well, Jim sent you a solution but I would rise a question, why do you want to do that. R has many instruments how to smoothly handle NA (missing values) but not many how to handle -9999 values. See ?na.omit na.action or na.rm parameters in many modelling or summary functions. Regards Petr> tried using is.na and the testdata[testdata$onecolumn==NA] <- 9999approach,> but whilst neither generate errors, neither result in -9999s appearing -the> NAs remain there! > > I'd be grateful for any advice on what I'm doing wrong or any othersuitable approaches.> > Many thanks, > > Steve > > _________________________________________________________________ > > oticons. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Perhaps testdata$onecolumn[testdata$onecolumn==NA] <- 9999 --- On Mon, 8/17/09, Steve Murray <smurray444 at hotmail.com> wrote:> From: Steve Murray <smurray444 at hotmail.com> > Subject: [R] Replacing NA values in one column of a data.frame > To: r-help at r-project.org > Received: Monday, August 17, 2009, 11:41 AM > > Dear all, > > I'm trying to replace NA values with -9999 in one column of > a data frame. I've tried using is.na and the > testdata[testdata$onecolumn==NA] <- 9999 approach, but > whilst neither generate errors, neither result in -9999s > appearing - the NAs remain there! > > I'd be grateful for any advice on what I'm doing wrong or > any other suitable approaches. > > Many thanks, > > Steve > > _________________________________________________________________ > > oticons. > > ______________________________________________ > R-help at 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. >__________________________________________________________________ [[elided Yahoo spam]]