Re: [R] Replecing empty values with a letter (continuation)

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Thu, 24 Apr 2008 01:33:44 +0000 (UTC)

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

______________________________________________
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.
Received on Thu 24 Apr 2008 - 01:37:39 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 24 Apr 2008 - 02:30:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive