Adds subtotal rows / sections (a la the 'SAS' 'Proc Tabulate' All option) to a Group By output by running a series of Group By functions with partial sets of the same variables and combining the results with the original. Can be used to add comprehensive information to a data report or to quickly aggregate Group By outputs used to gain a greater understanding of data.
The goal of ReportSubtotal is to adds subtotal rows / sections (a la SAS's Proc Tabulate) to a Group By output.
You can install the released version of ReportSubtotal from CRAN with:
install.packages("ReportSubtotal")
This is a basic example which shows you how to solve a common problem:
library(dplyr)
library(ReportSubtotal)
group_by(iris, Species, Petal.Width) %>%
summarise(Mean_Width = mean(Sepal.Width), .groups = "keep") %>%
subtotal_row(iris, vars = "Sepal.Width", aggregator = "mean")
group_by(mtcars, cyl, gear, carb) %>%
summarise(Med_Wt = median(wt), Med_Hp = median(hp), .groups = "keep") %>%
subtotal_row(mtcars, vars = c("wt", "hp"), aggregator = "median")