View source: R/summarize_across.R
summarize_across. | R Documentation |
Deprecated
Summarize multiple columns simultaneously
summarize_across.(
.df,
.cols = everything(),
.fns = NULL,
...,
.by = NULL,
.names = NULL
)
summarise_across.(
.df,
.cols = everything(),
.fns = NULL,
...,
.by = NULL,
.names = NULL
)
.df |
A data.frame or data.table |
.cols |
vector |
.fns |
Functions to pass. Can pass a list of functions. |
... |
Other arguments for the passed function |
.by |
Columns to group by |
.names |
A glue specification that helps with renaming output columns.
|
## Not run:
df <- data.table(
a = 1:3,
b = 4:6,
z = c("a", "a", "b")
)
# Pass a single function
df %>%
summarize_across.(c(a, b), mean, na.rm = TRUE)
# Single function using purrr style interface
df %>%
summarize_across.(c(a, b), ~ mean(.x, na.rm = TRUE))
# Passing a list of functions (with .by)
df %>%
summarize_across.(c(a, b), list(mean, max), .by = z)
# Passing a named list of functions (with .by)
df %>%
summarize_across.(c(a, b),
list(avg = mean,
max = ~ max(.x)),
.by = z)
# Use the `.names` argument for more naming control
df %>%
summarize_across.(c(a, b),
list(avg = mean,
max = ~ max(.x)),
.by = z,
.names = "{.col}_test_{.fn}")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.