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

Peter Alspach PAlspach at hortresearch.co.nz
Thu Apr 24 04:00:33 CEST 2008


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.



More information about the R-help mailing list