Add a content row of summary counts
summarize_row_groups(
lyt,
var = "",
label_fstr = "%s",
format = "xx (xx.x%)",
cfun = NULL,
indent_mod = 0L,
extra_args = list()
)
layout object pre-data used for tabulation
string, variable name
string. An sprintf style format string containing. For non-comparison splits, it can contain up to one "%s"
which takes the current split value and generates the row/column label. Comparison-based splits it can contain up to two "%s"
.
FormatSpec. Format associated with this split. Formats can be declared via strings ("xx.x"
) or function. In cases such as analyze
calls, they can character vectors or lists of functions.
list/function/NULL. tabulation function(s) for creating content rows. Must accept x
or df
as first parameter. Must accept labelstr
as the second argument. Can optionally accept all optional arguments accepted by analysis functions. See analyze
.
numeric. Modifier for the default indent position for the structure created by this function(subtable, content table, or row) and all of that structure's children. Defaults to 0, which corresponds to the unmodified default behavior.
list. Extra arguments to be passed to the tabulation function. Element position in thte list corresponds to the children of this split. Named elements in the child-specific lists are ignored if they do not match a formal argument of the ttabulation function.
A PreDataTableLayouts
object suitable for passing to further layouting functions, and to build_table
.
If format
expects 2 values (i.e. xx
appears twice in the format string, then both raw and percent of
column total counts are calculated. Otherwise only raw counts are used.
cfun
must accept df
as its first argument and 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
).
# 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