Skip to content

Instantly share code, notes, and snippets.

@romainfrancois
Created August 23, 2019 06:08
Show Gist options
  • Save romainfrancois/2237195c6dabb9274a6fe1e3ff6127ba to your computer and use it in GitHub Desktop.
Save romainfrancois/2237195c6dabb9274a6fe1e3ff6127ba to your computer and use it in GitHub Desktop.
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