# NOT RUN {
DM2 <- subset(DM, COUNTRY %in% c("USA", "CAN", "CHN"))
l <- basic_table() %>% split_cols_by("ARM") %>%
split_rows_by("COUNTRY", split_fun = drop_split_levels) %>%
summarize_row_groups(label_fstr = "%s (n)") %>%
analyze("AGE", afun = list_wrap_x(summary) , format = "xx.xx")
l
tbl <- build_table(l, DM2)
tbl
row_paths_summary(tbl) # summary count is a content table
## use a cfun and extra_args to customize summarization
## behavior
sfun <- function(x, labelstr, trim) {
in_rows(
c(mean(x, trim = trim), trim),
.formats = "xx.x (xx.x%)",
.labels = sprintf("%s (Trimmed mean and trim %%)",
labelstr)
)
}
l2 <- basic_table() %>% split_cols_by("ARM") %>%
split_rows_by("COUNTRY", split_fun = drop_split_levels) %>%
add_colcounts() %>%
summarize_row_groups("AGE", cfun = sfun,
extra_args = list(trim = .2)) %>%
analyze("AGE", afun = list_wrap_x(summary) , format = "xx.xx") %>%
append_topleft(c("Country", " Age"))
tbl2 <- build_table(l2, DM2)
tbl2
# }
Run the code above in your browser using DataLab