Computes a logical vector indicating which elements of x match the filter
criteria specified by val.
Details
The following arguments are supported in ...:
- column
When
xis a data.frame,columnis the name of the column intended to be filtered.- comparison
When
xis a numeric or Date andvalis a length-one numeric or Date,comparisonis the function used to comparexwithval. The default is<=.- gte
When
xis a numeric or Date andvalis a length-two numeric or Date,gtecontrols whether to use>=(TRUE, default) or>(FALSE) onval[[1]].- lte
When
xis a numeric or Date andvalis a length-two numeric or Date,ltecontrols whether to use<=(TRUE, default) or<(FALSE) onval[[2]].
Examples
df <- data.frame(
category = rep(letters[1:3], each = 4),
value = 1:12,
date = Sys.Date() + 0:11
)
# Filter character column
get_filter_logical(df, c("a", "b"), column = "category")
#> [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE
# Filter numeric column with single value
get_filter_logical(df, 5, column = "value", comparison = `<=`)
#> [1] TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
# Filter numeric column with range
get_filter_logical(df, c(3, 8), column = "value", gte = TRUE, lte = FALSE)
#> [1] FALSE FALSE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE