Created
August 23, 2019 06:08
-
-
Save romainfrancois/2237195c6dabb9274a6fe1e3ff6127ba 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(dplyr) | |
library(purrr) | |
df <- tribble( | |
~x, ~y, | |
"a", "b", | |
"c", "b", | |
"b", "a", | |
"b", "b", | |
"a", "a" | |
) | |
target <- tribble( | |
~x, ~y, | |
"a", "b", | |
"c", "b" | |
) | |
is_in <- function(x, y, target) { | |
any( | |
(target[[1]] == x & target[[2]] == y) | (target[[2]] == x & target[[1]] == y) | |
) | |
} | |
df %>% | |
mutate(test = map2_lgl(x, y, is_in, target = target)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment