I am utilizing gtsummary::tbl_summary to generate a data table. I am employing the following code to stratify it into two groups. My code gives "n" for the main category only. But I want to include "n" counts for each of the columns/groups, as illustrated in the attached figure. Can someone please help me
mtcars %>%
select(am, cyl, mpg, hp) %>%
dplyr::mutate(
cyl = paste(cyl, "Cylinder"),
am = factor(am, labels = c("Automatic", "Manual"))
) %>%
tbl_strata(
strata = cyl,
~.x %>%
tbl_summary(
by = am,
type = where(is.numeric) ~ "continuous"
) %>% add_n() %>%
modify_header(all_stat_cols() ~ "**{level}**")
)

You can dynamically add the column Ns using
modify_header(). Example below!