View source: R/colby_constructors.R
| summarize_row_groups | R Documentation |
Add a content row of summary counts
summarize_row_groups(
lyt,
var = "",
label_fstr = "%s",
format = "xx (xx.x%)",
na_str = "-",
cfun = NULL,
indent_mod = 0L,
extra_args = list()
)
lyt |
( |
var |
( |
label_fstr |
( |
format |
( |
na_str |
( |
cfun |
( |
indent_mod |
( |
extra_args |
( |
If format expects 1 value (i.e. it is specified as a format string and xx appears for two values
(i.e. xx appears twice in the format string) or is specified as a function, then both raw and percent of
column total counts are calculated. If format is a format string where xx appears only one time, only
raw counts are used.
cfun must accept x or df as its first argument. For the df argument cfun will receive the subset
data.frame corresponding with the row- and column-splitting for the cell being calculated. Must accept
labelstr as the second parameter, which accepts the label of the level of the parent split currently
being summarized. Can additionally take any optional argument supported by analysis functions. (see analyze()).
In addition, if complex custom functions are needed, we suggest checking the available additional_fun_params
that can be used in cfun.
A PreDataTableLayouts object suitable for passing to further layouting functions, and to build_table().
Gabriel Becker
DM2 <- subset(DM, COUNTRY %in% c("USA", "CAN", "CHN"))
lyt <- 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")
lyt
tbl <- build_table(lyt, 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
)
)
}
lyt2 <- basic_table(show_colcounts = TRUE) %>%
split_cols_by("ARM") %>%
split_rows_by("COUNTRY", split_fun = drop_split_levels) %>%
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(lyt2, DM2)
tbl2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.