library(dplyr)
dt <- data.frame(A=c(1,2), B=c(NA,5))
tbl_df(dt) %>% filter(A!=B)
I could get it that it can't compare > pr <. But it's kinda more intuitive to think NA is not equal to other values except other NA. Is there a work around to this?
library(dplyr)
dt <- data.frame(A=c(1,2), B=c(NA,5))
tbl_df(dt) %>% filter(A!=B)
I could get it that it can't compare > pr <. But it's kinda more intuitive to think NA is not equal to other values except other NA. Is there a work around to this?
One option would be to create another condition with is.na
tbl_df(dt) %>%
filter(A!=B| rowSums(is.na(.))>0)
# A B
# <dbl> <dbl>
#1 1 NA
#2 2 5
If we look at the output from the comparison
with(dt, A!=B)
#[1] NA TRUE
The first one returns NA
as any comparison with NA
returns NA
.