[R] Why can't R understand if(num!=NA)?

S Ellison S.Ellison at LGCGroup.com
Fri May 3 17:40:41 CEST 2013


 

> -----Original Message-----
> if(num!=NA)
> it yields an error message.

> Why doesn't the first statement work?
Because you just compared something with NA (usually interpreted as 'missing')  and because of that the comparison result is also NA. 
'if' then tells you that you have a missing value where you need either TRUE or FALSE.
Play with
num!=NA #returns NA
and
if(NA) "Not there"  #returns error

is.na() returns TRUE for NA's, so 'if' knows what to do with the answer.

S Ellison

*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}



More information about the R-help mailing list