tags:

views:

386

answers:

4

I have a table where there are "NA"s littered all over the place in one column in particular. I want to replace every instance of "NA" with something else -- say, the number 1.

How should I do that?

A: 

You can change the values with this SQL Statement.

Update TABLENAME
Set COLUMN_NAME = '1'
Where COLUMN_NAME = 'NA'

More info here

Etienne
Sorry, this was supposed to be in R. I don't know how the tags got changed.
Teef L
+1  A: 

Update Tablename set column='1' where column='NA'

valli
+4  A: 
x[is.na(x)] <- 1
Jonathan Chang
+1  A: 

Jonathan has the right answer for a vector, which you can apply to column a in data frame dat using:

> dat<-data.frame(a=c(11,2,11,NA),b=c(1,1,1,1))
> dat$a[is.na(dat$a)] <- 1

For completeness using Deducer's 'Recode Variables' dialog, which can do much more complicated recodings, produces the following code.

> library(Deducer)
> dat[c("a")] <- recode.variables(dat[c("a")] , "NA -> 1;")
Ian Fellows
Cool, didn't know about `Deducer`. And I think you can still use the succinct syntax `dat$a <- recode.variables(dat$a, "NA -> 1;")`.
Jonathan Chang
Deducer is a great tip. Thanks!
Teef L