applyFilterCriteria: Filter Rows from Data Frame Matching Criteria

View source: R/applyFilterCriteria.R

applyFilterCriteriaR Documentation

Filter Rows from Data Frame Matching Criteria

Description

Details about criteria applied and number of rows matching each criterion is returned in the attribute "details.filter". If a criterion evaluates to NA, the corresponding row in the data frame is removed (just as if the criterion evaluated to FALSE).

Usage

applyFilterCriteria(x, criteria = NULL, lengthColumn = NULL, ...)

Arguments

x

data frame

criteria

vector of character defining filter criteria to be evaluated in x

lengthColumn

name of the column containing lengths, e.g. "Length_raw"

...

passed to matchesCriteria

Examples

# Create a very simple data frame
df <- data.frame(value = 1:10, group = rep(c("a", "b"), 5))

# Show the data frame
df

# Filter for rows meeting two criteria
result <- applyFilterCriteria(df, c(
  "value is below or equal to 5" = "value <= 5", 
  "group is 'a'" = "group == 'a'"
))

# Show the result
result

# Get the evaluation of each criterion in columns
kwb.utils::getAttribute(result, "matches")


KWB-R/kwb.prep documentation built on June 11, 2022, 1:29 p.m.