View source: R/standalone-tidy-utils.R
summarise_with_totals | R Documentation |
Summarise and include a total row, or a row including the summary for the whole group, into a factor list. This looks and feels like a natural summarisation step, but applies the summarisation both to the subgroups and to the data ungrouped by one level. The additional group result is included as a new row. allows for a natural grouped and ungrouped summarisation
summarise_with_totals(
.data,
...,
.groups = NULL,
.total = "Total",
.total_first = FALSE
)
.data |
a dataframe |
... |
the summarisation specification |
.groups |
what to do with the grouping after summarisation (same as dplyr::summarise) |
.total |
name of the total row which will be added into a factor list. |
.total_first |
should the total be before or after the groups |
a summarised dataframe with the additional totals or group row
library(tidyverse)
diamonds %>%
dplyr::group_by(color,cut) %>%
summarise_with_totals(
mpg = sprintf("%1.1f \u00B1 %1.1f", mean(price), stats::sd(price)),
.total = "Overall"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.