I'm trying to execute the following code in R
comments = c("no","yes",NA)
for (l in 1:length(comments)) {
if (comments[l] != NA) print(comments[l]);
}
But I'm getting an error
Error in if (comments[l] != NA) print(comments[l]) : missing value where TRUE/FALSE needed
What's going on here?
This question is related to
r
if-statement
syntax
Can you change the if condition to this:
if (!is.na(comments[l])) print(comments[l]);
You can only check for NA values with is.na().
Source: Stackoverflow.com