Description Usage Arguments Value Examples
This function is inteded to extend the 'summarise' function in dplyr by binding (using 'bind_row') a "Total" row to the dataframe. This is especially useful when generating reports that require a summary line. It also appropriatly scales everything to make sure that aggregate functions such as 'mean' are taken on the raw data and not the aggregate data.
1 |
.data |
A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr). See Methods, below, for more details. |
... |
< The value can be:
|
label |
what should the total row be labeled as? Only valid if the first grouping variables is a factor or character. |
An object of the same class as .data. One grouping level will be dropped.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | library(dplyr)
# cyl is a number so it's not possible to label the "Total Row"
mtcars %>%
group_by(cyl) %>%
rollup(mean = mean(disp), n = n())
# Casting cyl to a character allows automatic labeling of the final row.
mtcars %>%
mutate(cyl = as.character(cyl)) %>%
group_by(cyl) %>%
rollup(sum = sum(disp),
mean = mean(disp),
sd = sd(disp),
n = n())
# Set label = NA to not label the last row (same as if it's a number)
mtcars %>%
mutate(cyl = as.character(cyl)) %>%
group_by(cyl) %>%
rollup(sum = sum(disp),
mean = mean(disp),
sd = sd(disp),
n = n(),
label = NA)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.