For each desired row, check if all/any/none of the columns fulfill a given comparison, return the index of the first column that fulfills the comparison, or the number of columns that do.

row_compare(.data, match_type = "none", operator = "==", values = 0L, ...)

# S3 method for matrix
row_compare(.data, match_type = "none", operator = "==", values = 0L, ...)

# S3 method for data.frame
row_compare(.data, match_type = "none", operator = "==", values = 0L, ...)

Arguments

.data

A two-dimensional data structure.

match_type

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

operator

A character indicating the comparison operator. See details.

values

The value or list of values to compare against. See details.

...

Arguments passed on to op_ctrl

output_class

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

na_action

One of ("exclude", "pass"), possibly abbreviated. See stats::na.pass for semantics.

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 character in operator should match one of the base::Comparison operators. You can also pass "is", which is an alias for "==", but might convey code semantics better in case values contain NA or Inf.

If values is not a list, it will be coerced to one with base::as.list(). Each element in the list must have length equal to 1. The values are recycled in order to match the number of columns in .data.

Type promotion/conversion will follow normal R rules.

The na_action from op_ctrl() is only relevant when a value from values is not NA.

Note

Note that string comparison follows C++ rules.

Examples

row_compare(data.frame(0L, 1.0, "0", TRUE, 0+0i), "all", "==", values = list(0L, 1L))
#> [1] TRUE
row_compare(data.frame(NA_integer_, NA_real_, NA_character_, NA, NA_complex_), "all", "is", values = NA)
#> [1] TRUE