[R] Logical Operators' inconsistent Behavior

Thierry Onkelinx thierry.onkelinx at inbo.be
Fri May 19 11:58:00 CEST 2017


& -> AND -> results only TRUE if both inputs are TRUE. Hence: FALSE AND
unknown = FALSE, TRUE AND unknown = unknown
| -> OR -> results in TRUE as soon as one of the inputs is TRUE. Hence FASE
or unknown = unknown, TRUE or unknown = TRUE
TRUE == NA and FALSE == NA compares TRUE/FALSE against unknown hence the
output is unknown.

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

2017-05-19 11:48 GMT+02:00 Ramnik Bansal <ramnik.bansal op gmail.com>:

> 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
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help op r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list