Wednesday 28 October 2015

Deal with Missing Data NA in R

Firstly, Yes, there is no " " on NA.

I wrote something like
                   if(mat[i,j] == "NA"){...}

Please don't laugh at me R users...

I got my answer from the following post:
 http://stackoverflow.com/questions/27018471/r-missing-value-where-true-false-needed

comments = c("no","yes",NA)
for (l in 1:length(comments)) {
    if (!is.na(comments[l])) print(comments[l])
}
[1] "no"
[1] "yes"
So the function is.na is the way to do the judgement. And yes use NA directly, no need to quote.

No comments:

Post a Comment