Use the is.na function. There is no need to convert to a factor, although the fact that you had character meanings caused you to be numeric.
> df <- data.frame("h"=c(1,1,".")) > is.na(df) <- df=="." > df h 1 1 2 1 3 <NA>
I'm not sure why @TylerRinker deleted his answer regarding the use of "na.strings" since I thought this was the correct answer.
Comment: looking at this a year later, I realized that a) the PR incorrectly understood how the values were absent when they were in factors or symbol vectors, and b) that the main problem was not an error when transcoding to the R-missing value, which is the code The OP has already done the right thing, but rather was a bug with the bug that @joran identified.
source share