| mutate_sd {table.express} | R Documentation |
Mutate subset of data
Description
Like mutate-table.express but possibly recycling calls.
Usage
mutate_sd(.data, .SDcols, .how = identity, ...)
## S3 method for class 'ExprBuilder'
mutate_sd(
.data,
.SDcols,
.how = identity,
...,
.pairwise = TRUE,
.prefix,
.suffix,
.parse = getOption("table.express.parse", FALSE),
.chain = getOption("table.express.chain", TRUE)
)
## S3 method for class 'EagerExprBuilder'
mutate_sd(.data, ..., .parent_env = rlang::caller_env())
## S3 method for class 'data.table'
mutate_sd(.data, ...)
Arguments
.data |
An instance of ExprBuilder. |
.SDcols |
See data.table::data.table and the details here. |
.how |
The function(s) or function call(s) that will perform the transformation. If many,
a list should be used, either with |
... |
Possibly more arguments for all functions/calls in |
.pairwise |
If |
.prefix, .suffix |
Only relevant when |
.parse |
Logical. Whether to apply |
.chain |
Logical. Should a new frame be automatically chained to the expression if the clause being set already exists? |
.parent_env |
See |
Details
This function works similar to transmute_sd() but keeps all columns and can modify by
reference, like mutate-table.express. It can serve like
dplyr's scoped mutation variants depending on what's given to .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) %>%
start_expr %>%
mutate_sd(c("mpg", "cyl"), ~ .x * 2)