library(dplyr)
this_summary <- function(.data) {
summarize(.data,
qwraps2::frmt(min(mpg)),
qwraps2::frmt(median(mpg)),
qwraps2::frmt(max(mpg)),
qwraps2::frmt(min(hp)),
qwraps2::frmt(max(hp)),
qwraps2::frmt(mean(wt)))
}
mtcars$cyl_factor <- factor(mtcars$cyl, levels = c(4, 6, 8))
tab <- cbind(mtcars %>% this_summary %>% t,
mtcars %>% group_by(cyl_factor) %>% this_summary %>% t %>% {.[-1, ]})
rwgrp <- c("Miles Per Gallon" = 3, "Horse Power" = 2, "Weight" = 1)
rwnms <- c("Min MPG", "Median MPG", "Max MPG", "Min HP", "Max HP", "Mean Weight")
cnms <- c("All mtcars", paste(levels(mtcars$cyl_factor), "Cyl"))
qable(tab, rwgrp, rwnms, cnms, markup = "latex")
qable(tab, rwgrp, rwnms, cnms, markup = "markdown")
Run the code above in your browser using DataLab