Created
January 30, 2019 22:45
-
-
Save bhive01/2032b90435196bbe2cc4dcfa55b093eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
not_the_fucking_same <- function(x, y, keepNAs = "all") { | |
if (keepNAs == "all") { | |
x != y | is.na(x) | is.na(y) | |
} else if (keepNAs == "x") { | |
x != y | is.na(x) | |
} else if (keepNAs == "y") { | |
x != y | is.na(y) | |
} else { | |
stop("WTF input?") | |
} | |
} | |
d_f <- tibble(x = c(0,1,2,NA,4), y = c(0,NA,2,3,5)) | |
d_f %>% filter(x != y | is.na(x) | is.na(y)) | |
#doesn't work with NAs | |
d_f %>% filter(Vectorize(identical)(x,y)) | |
d_f %>% filter(Vectorize(isTRUE)(x,y)) | |
d_f %>% filter(not_the_fucking_same(x,y)) | |
d_f %>% filter(not_the_fucking_same(x,y, "x")) | |
d_f %>% filter(not_the_fucking_same(x,y, "y")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment