For dplyr and tidyverse you can use dplyr:anti_join() . According to his documentation, dplyr::anti_join(x, y) "returns all rows from x , where y does not have corresponding values, preserving only columns from x ." Therefore, for dplyr::anti_join(row, df) result has zero rows, then row really was in df , if it has one row, then row not in df .
library(dplyr) df <- tribble(~a, ~b, 1, "cat", 2, "dog") #> # A tibble: 2 x 2 #> ab #> <dbl> <chr> #> 1 1.00 cat #> 2 2.00 dog row <- tibble(a = 1, b = "cat") #> # A tibble: 1 x 2 #> ab #> <dbl> <chr> #> 1 1.00 cat nrow(anti_join(row, df)) == 0 # row is in df so should be TRUE #> Joining, by = c("a", "b") #> [1] TRUE row <- tibble(a = 3, b = "horse") #> # A tibble: 1 x 2 #> ab #> <dbl> <chr> #> 1 3.00 horse nrow(anti_join(row, df)) == 0 # row is not in df so should be FALSE #> Joining, by = c("a", "b") #> [1] FALSE
Rory nolan
source share