Why is this so in R
?
> F & NA
[1] FALSE
> T & NA
[1] NA
I would expect the first line of the code to evaluate to NA
as well. People have told me 'this is simply strange behavior of R', but is there some other notion to it?
Why is this so in R
?
> F & NA
[1] FALSE
> T & NA
[1] NA
I would expect the first line of the code to evaluate to NA
as well. People have told me 'this is simply strange behavior of R', but is there some other notion to it?
If you have an AND (&
) statement and one of the values is false, then it doesn't matter what the other value is, the answer is going to be false. The NA
value means that a value is missing, but the unobserved value must be a true or false and either way you're going to get false back.
But if one of the values is true, then the AND will only be true if the second value is also true. However in this case the missing value (NA), could be true or false so it's impossible to say whether the expression will be. Thus R has to propagate the NA value.