Check whether values in a vector are in or not in another vector.

Built using data.table::'%chin%' and vctrs::vec_in() for performance.

x %in% y

x %notin% y

Arguments

x

A vector of values to check if they exist in y

y

A vector of values to check if x values exist in

Details

Falls back to base::'%in%' when x and y don't share a common type. This means that the behaviour of base::'%in%' is preserved (e.g. "1" %in% c(1, 2) is TRUE) but loses the speedup provided by vctrs::vec_in().

Examples

df <- tidytable(x = 1:4, y = 1:4)

df %>%
  filter(x %in% c(2, 4))
#> # A tidytable: 2 × 2
#>       x     y
#>   <int> <int>
#> 1     2     2
#> 2     4     4

df %>%
  filter(x %notin% c(2, 4))
#> # A tidytable: 2 × 2
#>       x     y
#>   <int> <int>
#> 1     1     1
#> 2     3     3