[R] Replecing empty values with a letter (continuation)
David Winsemius
dwinsemius at comcast.net
Thu Apr 24 03:33:44 CEST 2008
Judith Flores <juryef at yahoo.com> wrote in
news:32500.45083.qm at web34708.mail.mud.yahoo.com:
> Sorry, I hit the send botton by accident. Here is my
> code so far:
>
> dat<-read.csv('myfile.csv', na.strings="")
> dat[is.na(dat]<-'N'
>
> But it doesn't replace the <NA> for the letter 'N'.
>
>
What happens when you just type:
dat[is.na(dat)] #?
My guess is that you don't have any, since na.strings="" told
read.table that there were no values that should be assigned <NA>. It
is possible to have a value of "NA" that is not <NA>.
> x <- c("NA", 1 , 2)
#NA is not <NA>
> is.na(x)
[1] FALSE FALSE FALSE
> txt <- "nnn 1 2 3 4 5"
> xt<- read.table(textConnection(txt), header=FALSE)
> xt
V1 V2 V3 V4 V5 V6
1 nnn 1 2 3 4 5
> xt<- read.table(textConnection(txt), header=FALSE,na.strings="nnn")
> xt
V1 V2 V3 V4 V5 V6
1 NA 1 2 3 4 5
#That is a TRUE >NA>
> is.na(xt)
V1 V2 V3 V4 V5 V6
[1,] TRUE FALSE FALSE FALSE FALSE FALSE
> xt[is.na(xt)] <- "N"
> xt
V1 V2 V3 V4 V5 V6
1 N 1 2 3 4 5
--
David Winsemius
More information about the R-help
mailing list