Check if a row's columns' values are present in a set of known values

row_in(.data, match_type = "none", sets = list(), negate = FALSE, ...)

# S3 method for matrix
row_in(.data, match_type = "none", sets = list(), negate = FALSE, ...)

# S3 method for data.frame
row_in(.data, match_type = "none", sets = list(), negate = FALSE, ...)

Arguments

.data

A two-dimensional data structure.

match_type

One of ("all", "any", "none", "which_first", "count"). Possibly abbreviated.

sets

The list of sets to compare against. See details.

negate

Logical. If TRUE, values that are not in the sets are sought.

...

Arguments passed on to op_ctrl

output_class

One of ("vector", "list", "data.frame", "matrix"), possibly abbreviated.

cols

A vector indicating which columns to consider for the operation. If NULL, all columns are used. If its length is 0, no columns are considered. Negative numbers, logical values, character vectors representing column names, and tidyselect::select_helpers are supported.

rows

Like cols but for row indices, and without tidyselect support.

factor_mode

One of ("character", "integer"), possibly abbreviated. If a column is a factor, this determines whether the operation uses its internal integer values, or the character values from its levels.

Details

The sets are recycled in order to match the number of columns in .data.

Type promotion/conversion will follow normal R rules.

Note

Note that string comparison follows C++ rules.

Examples

mat <- matrix(sample(letters, 10), nrow = 5L, ncol = 2L) # count how many columns are in a chosen subset row_in(mat, "count", list(c("a", "b")))
#> [1] 0 0 0 0 0
# careful if complex numbers are involved row_in(data.frame(-1 + 0i, 1/3 + 0i), "all", list(-1L, 1/3))
#> [1] TRUE
row_in(data.frame(-1 + 1i, 1/3 - 1i), "none", list(-1L, 1/3))
#> [1] TRUE