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

From: Peter Alspach <PAlspach_at_hortresearch.co.nz>
Date: Thu, 24 Apr 2008 14:00:33 +1200

Judith

I think you'll find the issue is that read.csv creates a data.frame and your subsetting syntax
dat[is.na(dat)] is assuming it to be a matrix. If this is the case, you have two options:

Coerce dat into a matrix with as.matrix(dat); Use apply() to replace the missing data for each column in turn ... apply(dat, 2, function(x) x[is.na(x)] <- 'N')

HTH ....... Peter Alspach

> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] On Behalf Of Judith Flores
> Sent: Thursday, 24 April 2008 11:20 a.m.
> To: RHelp
> Subject: [R] Replecing empty values with a letter (continuation)
>
> 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'.
>
>
> I am using R v 2/7/0, running it under Windows XP.
>
> Thank you,
>
> Judith
>
>
>
> ______________________________________________________________
> ______________________
> Be a better friend, newshound, and
>
> ______________________________________________
> 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.
>

The contents of this e-mail are privileged and/or confidential to the named  recipient and are not to be used by any other person and/or organisation.  If you have received this e-mail in error, please notify the sender and delete  all material pertaining to this e-mail.



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 - 02:05:26 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 - 03:30:40 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