Skip to contents

Filters `data` by retaining rows whose values match at least one row in `criteria` for the selected columns.

Usage

filter_matching(data, criteria, cols = NULL)

Arguments

data

A data frame.

criteria

A data frame, or an object coercible to a data frame, containing the values to match.

cols

Character vector specifying the columns used for matching. If `NULL`, all columns in `criteria` are used.

Value

A data frame containing the rows of `data` matching at least one row in `criteria`.

Details

Each row of `criteria` represents a combination of values to match. Multiple rows are therefore combined using OR logic, while values within a row are combined using AND logic.

Examples

data <- data.frame(
  x = c(1, 1, 2, 2),
  y = c("a", "b", "a", "b"),
  z = 1:4
)

filter_matching(
  data,
  data.frame(x = 1, y = "a")
)
#>   x y z
#> 1 1 a 1

filter_matching(
  data,
  data.frame(
    x = c(1, 2),
    y = c("a", "b")
  )
)
#>   x y z
#> 1 1 a 1
#> 2 2 b 4