Home dplyr summarize with subtotals
 One of the great things about pivot tables in excel is that they provide subtotals automatically. First, I would like to know if there is anything already created within dplyr that can accomplish this. If not, what is the easiest way to achieve it? In the example below, I show the mean displacement by number of cylinders and carburetors. For each group of cylinders (4,6,8), I'd like to see the mean displacement for the group (or total displacement, or any other summary statistic). library(dplyr) mtcars %>% group_by(cyl,carb) %>% summarize(mean(disp)) cyl carb mean(disp) 1 4 1 91.38 2 4 2 116.60 3 6 1 241.50 4 6 4 163.80 5 6 6 145.00 6 8 2 345.50 7 8 3 275.80 8 8 4 405.50 9 8 8 301.00