[R] [FORGED] Logical Operators' inconsistent Behavior

Jérémie Juste jeremiejuste at gmail.com
Fri May 19 14:01:54 CEST 2017


Hello,

Rolf said,

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.


According to this logic why is

> FALSE & NA
>
[1] FALSE
?

Best regards,

Jeremie

On Fri, May 19, 2017 at 1:38 PM, S Ellison <S.Ellison at lgcgroup.com> wrote:

> > 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.
> >
> > As I said *think* about it; don't just go with your immediate knee-jerk
> > (simplistic) reaction.
>
> Hmm... not sure that was quite fair to the OP. Yes,  FALSE & <anything> ==
> FALSE. But 'NA' does not mean 'anything'; it means 'missing' (see ?'NA').
> It is much less obvious that FALSE & <missing> should generate a
> non-missing value. SQL, for example, generally  takes the view that any
> expression involving 'missing' is 'missing'.
>
> And R's behaviour can look odd if the vagaries of real data intervene:
> b1 <- c(A=TRUE, C=FALSE)
> b2 <- c(A=FALSE, B=FALSE, C=TRUE)
> b1['B'] & b2['B']
> #Which returns
> # <NA>
> # FALSE
>
> which - particularly since it appears without warning - is not an
> obviously sensible outcome.
>
> I am not suggesting a change to R's logical operations, which have clearly
> been thought through (that is evident from NA&FALSE == FALSE&NA == FALSE).
> But R's behaviour looks to me like a choice among difficult alternatives,
> rather than the only possible choice. I'd give the OP some credit for that.
>
> S Ellison
>
>
> S Ellison
>
>
>
>
>
>
>
> *******************************************************************
> This email and any attachments are confidential. Any u...{{dropped:18}}



More information about the R-help mailing list