With the package qwraps2 we can create nice summary tables in HTML and Latex.
Grouped data.frames with one group are supported as well but what about nested groups? Is there a way to directly pass a data.frame with nested groups to qwraps2::summary_table()?
Alternatively, is there a way to cbind() two outputs?
Consider the following:
R code
library(dplyr)
library(qwraps2)
our_summary1 <-
list("Miles Per Gallon" =
list("min" = ~ min(.data$mpg),
"max" = ~ max(.data$mpg),
"mean (sd)" = ~ qwraps2::mean_sd(.data$mpg)),
"Displacement" =
list("min" = ~ min(.data$disp),
"median" = ~ median(.data$disp),
"max" = ~ max(.data$disp),
"mean (sd)" = ~ qwraps2::mean_sd(.data$disp)),
"Weight (1000 lbs)" =
list("min" = ~ min(.data$wt),
"max" = ~ max(.data$wt),
"mean (sd)" = ~ qwraps2::mean_sd(.data$wt)),
"Forward Gears" =
list("Three" = ~ qwraps2::n_perc0(.data$gear == 3),
"Four" = ~ qwraps2::n_perc0(.data$gear == 4),
"Five" = ~ qwraps2::n_perc0(.data$gear == 5))
)
summary_table(mtcars %>% dplyr::group_by(vs), our_summary1)

I would like to group by vs and gear however. Each vs group would consequently have three gear subgroups (gear == 3, 4, or 5).
The following results in an error:
summary_table(mtcars %>% dplyr::group_by(vs, gear), our_summary1)
Error in dimnames(x) <- dn : length of 'dimnames' [1] not equal to array extent
You can add a column manually or use
interaction(vs, gear)for grouping: