Deprecated
Mutate multiple columns simultaneously.
mutate_across.(
.df,
.cols = everything(),
.fns = NULL,
...,
.by = NULL,
.names = NULL
)
A data.frame or data.table
vector c()
of unquoted column names. tidyselect
compatible.
Functions to pass. Can pass a list of functions.
Other arguments for the passed function
Columns to group by
A glue specification that helps with renaming output columns.
{.col}
stands for the selected column, and {.fn}
stands for the name of the function being applied.
The default (NULL
) is equivalent to "{.col}"
for a single function case and "{.col}_{.fn}"
when a list is used for .fns
.
if (FALSE) {
df <- data.table(
x = rep(1, 3),
y = rep(2, 3),
z = c("a", "a", "b")
)
df %>%
mutate_across.(where(is.numeric), as.character)
df %>%
mutate_across.(c(x, y), ~ .x * 2)
df %>%
mutate_across.(everything(), as.character)
df %>%
mutate_across.(c(x, y), list(new = ~ .x * 2,
another = ~ .x + 7))
df %>%
mutate_across.(
.cols = c(x, y),
.fns = list(new = ~ .x * 2, another = ~ .x + 7),
.names = "{.col}_test_{.fn}"
)
}