if statement - R - " missing value where TRUE/FALSE needed " -


this question has answer here:

i'm trying execute following code in r

comments = c("no","yes",na) (l in 1:length(comments)) {     if (comments[l] != na) print(comments[l]); } 

but i'm getting error

error in if (comments[l] != na) print(comments[l]) : missing value true/false needed 

what's going on here?

check command : na!=na : you'll result na, hence error message.

you have use function is.na ifstatement work (in general, better use function check na values) :

comments = c("no","yes",na) (l in 1:length(comments)) {     if (!is.na(comments[l])) print(comments[l]) } [1] "no" [1] "yes" 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -