
Last chance! 50% off unlimited learning
Sale ends in
These are methods for the dplyr mutate()
and transmute()
generics.
They are translated to computed expressions in the SELECT
clause of
the SQL query.
# S3 method for tbl_lazy
mutate(
.data,
...,
.by = NULL,
.keep = c("all", "used", "unused", "none"),
.before = NULL,
.after = NULL
)
Another tbl_lazy
. Use show_query()
to see the generated
query, and use collect()
to execute the query
and return data to R.
A lazy data frame backed by a database query.
<data-masking
> Variables, or functions of
variables. Use desc()
to sort a variable in descending order.
<tidy-select
> Optionally, a selection of columns to
temporarily group by using an inline alternative to group_by()
.
Control which columns from
.data
are retained in the output. Grouping
columns and columns created by ...
are always kept.
"all"
retains all columns from .data
. This is the default.
"used"
retains only the columns used in ...
to create new
columns. This is useful for checking your work, as it displays inputs
and outputs side-by-side.
"unused"
retains only the columns not used in ...
to create new
columns. This is useful if you generate new columns, but no longer need
the columns used to generate them.
"none"
doesn't retain any extra columns from .data
. Only the grouping
variables and columns created by ...
are kept.
<
tidy-select
> Optionally, control where new columns
should appear (the default is to add to the right hand side). See
relocate()
for more details.
library(dplyr, warn.conflicts = FALSE)
db <- memdb_frame(x = 1:5, y = 5:1)
db %>%
mutate(a = (x + y) / 2, b = sqrt(x^2L + y^2L)) %>%
show_query()
# dbplyr automatically creates subqueries as needed
db %>%
mutate(x1 = x + 1, x2 = x1 * 2) %>%
show_query()
Run the code above in your browser using DataLab