[R] [FORGED] Logical Operators' inconsistent Behavior

Rolf Turner r.turner at auckland.ac.nz
Fri May 19 12:05:11 CEST 2017


On 19/05/17 21:48, Ramnik Bansal wrote:

> Hi,
>
> I need to understand the inconsistent behaviour of & and I operators when
> used with NA.
>
> The code below explains this inconsistency
>
>> TRUE & NA
> [1] NA
>
>> FALSE & NA
> [1] FALSE
>
>> TRUE & NA
> [1] NA
>
>> FALSE | NA
> [1] NA
>
>> TRUE | NA
> [1] TRUE
>
>> TRUE == NA
> [1] NA
>
>> FALSE == NA
> [1] NA

What inconsistency?  It all makes complete sense.  Think about it.

TRUE & FALSE is FALSE but TRUE & TRUE is TRUE, so TRUE & NA could be
either TRUE or FALSE and consequently is NA.

OTOH FALSE & (anything) is FALSE so FALSE & NA is FALSE.

Und so weiter.

As I said *think* about it; don't just go with your immediate knee-jerk 
(simplistic) reaction.

cheers,

Rolf Turner

-- 
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276



More information about the R-help mailing list