gjanesch / data-and-the-world

Blog content.
0 stars 0 forks source link

Booleans & NAs - Data & The World #4

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

Booleans & NAs - Data & The World

A quick look at interactions with NAs and boolean operators.

https://data-and-the-world.onrender.com/posts/booleans-and-nas/

aviast commented 3 years ago

There’s an argument to be made for Boolean expressions short-circuiting to “missing” or “NA”

No, there isn't. Short circuiting is about avoiding computation that is not necessary to arrive at the correct result. The result must still be correct though.

NA means the value is not known. Therefore NA is a placeholder for the set of all possible values.

In the case of a Boolean variable NA represents TRUE and FALSE. So: NA & TRUE evaluates to the result of TRUE & TRUE (TRUE) and FALSE & TRUE (FALSE). The outcomes TRUE and FALSE are represented by... NA!

However NA & FALSE evaluates as TRUE & FALSE (FALSE) and FALSE & FALSE (FALSE). The outcomes FALSE and FALSE are represented by FALSE. The suggestion that this should evaluate to NA is just wrong.

I hope this makes sense.