| filter_sd {table.express} | R Documentation |
Filter subset of data
Description
Helper to filter rows with the same condition applied to a subset of the data.
Usage
filter_sd(.data, .SDcols, .how = Negate(is.na), ...)
## S3 method for class 'ExprBuilder'
filter_sd(
.data,
.SDcols,
.how = Negate(is.na),
...,
which,
.collapse = `&`,
.parse = getOption("table.express.parse", FALSE),
.chain = getOption("table.express.chain", TRUE),
.caller_env_n = 1L
)
## S3 method for class 'data.table'
filter_sd(.data, ..., .expr = FALSE)
Arguments
.data |
An instance of ExprBuilder. |
.SDcols |
See data.table::data.table and the details here. |
.how |
The filtering function or predicate. |
... |
Possibly more arguments for |
which |
Passed to data.table::data.table. |
.collapse |
See where-table.express. |
.parse |
Logical. Whether to apply |
.chain |
Logical. Should a new frame be automatically chained to the expression if the clause being set already exists? |
.caller_env_n |
Internal. Passed to |
.expr |
If the input is a |
Details
This function adds/chains an i expression that will be evaluated by data.table::data.table,
and it supports the .COL pronoun and lambdas as formulas. The .how condition is applied to
all .SDcols.
Additionally, .SDcols supports:
A predicate using the
.COLpronoun that should return a single logical when.COLis replaced by a column of the data.A formula using
.or.xinstead of the aforementioned.COL.
The caveat is that the expression is evaluated eagerly, i.e. with the currently captured
data.table. Consider using chain() to explicitly capture intermediate results as actual
data.tables.
To see more examples, check the vignette, or the table.express-package entry.
Examples
data("mtcars")
data.table::as.data.table(mtcars) %>%
filter_sd(c("vs", "am"), ~ .x == 1)