[R] converting blank cells to NAs

arun smartpink111 at yahoo.com
Tue Apr 16 15:38:03 CEST 2013


Hi,
I am not sure about the problem.
If your non-numeric vector is like:
a,b,,d,e,,f

vec1<-unlist(str_split(readLines(textConnection("a,b,,d,e,,f")),","))
 vec1[vec1==""]<- NA
 vec1
#[1] "a" "b" NA  "d" "e" NA  "f"

If this doesn't work, please provide an example vector.
A.K.



>Thanks for the response.  That seems to do the trick as far replacing the empty 
cells with <NA>, however, the problem remains that the vector is 
not >numeric.  This was the reason I wanted to replace the empty cells 
with NAs in the first place.  Forcing the vector with as.numeric 
afterwards doesn't >seem to work either, I get nonsensical results.



More information about the R-help mailing list