[R] How to convert blanks to NA
John Kane
jrkrideau at yahoo.ca
Tue Jun 2 21:51:42 CEST 2009
Does this do what you want
x <- data.frame(1,"" , 5)
x[x==""] <- NA
x
where x is substituted for your 'data'?
----- Original Message ----
From: Mark Na <mtb954 at gmail.com>
To: r-help at r-project.org
Sent: Tuesday, June 2, 2009 3:14:00 PM
Subject: [R] How to convert blanks to NA
Hi R-helpers,
I have imported data from Excel using the following code:
library(xlsReadWrite)
data <- read.xls(data,colClasses=c("character"))
and this results in all of the empty (blank) cells in the imported
Excel file also being empty (blank) in the resulting dataframe.
I am not used to having blanks (rather NAs) and I think these are
caused by the colClasses argument.
I would like to convert all the empty (blank) cells in my dataframe to NA.
Thanks for any help you might provide.
Mark
______________________________________________
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.
More information about the R-help
mailing list