When we need rows to reflect different variables rather than different
levels of a single variable, we use split_rows_by_multivar
.
Arguments
- lyt
layout object pre-data used for tabulation
- vars
character vector. Multiple variable names.
- split_fun
function/NULL. custom splitting function See
custom_split_funs
- split_label
string. Label string to be associated with the table generated by the split. Not to be confused with labels assigned to each child (which are based on the data and type of split during tabulation).
- varlabels
character vector. Labels for
vars
- format
FormatSpec. Format associated with this split. Formats can be declared via strings (
"xx.x"
) or function. In cases such asanalyze
calls, they can character vectors or lists of functions.- na_str
character(1). String that should be displayed when the value of
x
is missing. Defaults to"NA"
.- nested
boolean. Should this layout instruction be applied within the existing layout structure if possible (
TRUE
, the default) or as a new top-level element (`FALSE). Ignored if it would nest a split underneath analyses, which is not allowed.- child_labels
string. One of
"default"
,"visible"
,"hidden"
. What should the display behavior be for the labels (ie label rows) of the children of this split. Defaults to"default"
which flags the label row as visible only if the child has 0 content rows.- indent_mod
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.
- section_div
character(1). String which should be repeated as a section divider after each group defined by this split instruction, or
NA_character_
(the default) for no section divider.- extra_args
list. Extra arguments to be passed to the tabulation function. Element position in the 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 tabulation function.
Value
A PreDataTableLayouts
object suitable for passing to further
layouting functions, and to build_table
.
See also
split_rows_by()
for typical row splitting, and
split_cols_by_multivar()
to perform the same type of split on a column basis.
Examples
lyt <- basic_table() %>%
split_cols_by("ARM") %>%
split_rows_by_multivar(c("SEX", "STRATA1")) %>%
summarize_row_groups() %>%
analyze(c("AGE", "SEX"))
tbl <- build_table(lyt, DM)
tbl
#> A: Drug X B: Placebo C: Combination
#> —————————————————————————————————————————————————————————————————————
#>
#> SEX 121 (100.0%) 106 (100.0%) 129 (100.0%)
#> AGE
#> Mean 34.91 33.02 34.57
#> SEX
#> F 70 56 61
#> M 51 50 68
#> U 0 0 0
#> UNDIFFERENTIATED 0 0 0
#> STRATA1 121 (100.0%) 106 (100.0%) 129 (100.0%)
#> AGE
#> Mean 34.91 33.02 34.57
#> SEX
#> F 70 56 61
#> M 51 50 68
#> U 0 0 0
#> UNDIFFERENTIATED 0 0 0