Equality operator that is NA-aware
grapes-equals-grapes.RdInfix equality operator that resolves missing values instead of propagating them.
Details
base::== returns NA whenever either operand is NA.
%==% resolves those positions and never returns NA.
For each pair of compared elements the result is
TRUEwhen bothxandyareNA.FALSEwhen exactly one ofxandyisNA.The value of
x == ywhen neither isNA.
NaN is treated the same as NA, because is.na(NaN) is TRUE.
NaN %==% NaN is TRUE and NaN %==% NA is TRUE.
x and y are recycled to a common length following standard R rules.
Examples
#----------------------------------------------------------------------------
# %==% examples
#----------------------------------------------------------------------------
library(bkbase)
# both NA gives TRUE, exactly one NA gives FALSE
1:3 %==% c(1:2, NA) # TRUE TRUE FALSE
#> [1] TRUE TRUE FALSE
NA %==% NA # TRUE
#> [1] TRUE
# NaN is treated the same as NA
1:3 %==% c(1:2, NaN) # TRUE TRUE FALSE
#> [1] TRUE TRUE FALSE
NaN %==% NaN # TRUE
#> [1] TRUE
NaN %==% NA # TRUE
#> [1] TRUE
# base `==` propagates NA instead
1:3 == c(1:2, NA) # TRUE TRUE NA
#> [1] TRUE TRUE NA
1:3 == c(1:2, NaN) # TRUE TRUE NA
#> [1] TRUE TRUE NA