tbl_split_by_rows() and tbl_split_by_columns() split one table into a
list of tables, by rows of x$table_body or by groups of its columns. The
result prints one table after another, and both functions also accept the
list another split produced, so row and column splits combine into a
single flat list.
Run show_header_names() to list the column names to split by.
Usage
tbl_split_by_rows(
x,
variables = NULL,
row_numbers = NULL,
variable_level = NULL,
footnotes = c("all", "first", "last"),
caption = c("all", "first", "last")
)
tbl_split_by_columns(
x,
keys,
groups,
footnotes = c("all", "first", "last"),
caption = c("all", "first", "last")
)
# S3 method for class 'ltsummary_split'
print(x, ...)
# S3 method for class 'ltsummary_split'
knit_print(x, ...)
# S3 method for class 'ltsummary_split'
record_print(x, ...)
# S3 method for class 'ltsummary_split'
pkgdown_print(x, visible = TRUE)Arguments
- x
(
ltsummaryorlist)
An ltsummary object, or the list of tables another split returned. When a chained split receives a list, only thevariablesargument (rows) or thekeysandgroupsarguments (columns) carry over to the pieces.- variables
(selector)
The table is separated after each of the selected variables.x$table_bodymust contain avariablecolumn to use this argument.- row_numbers
(
integer)
Row numbers after which the table is split. The last row never starts a new table, as its split happens after it. Use one ofvariables,row_numbersandvariable_level.- variable_level
(selector)
A single column ofx$table_body; the table is split at each of its unique values, and each returned table carries its value as thevariable_levelattribute.- footnotes, caption
(
string)"all"(the default),"first"or"last": which tables keep the abbreviations and source notes (footnotes) and the caption. Numbered reference footnotes are always present wherever they appear.- keys
(selector)
Columns repeated in every table. Defaults to the first column that is shown, usually the label column.- groups
(list of
charactervectors)
Column names ofx$table_body; each group becomes one table. Shown columns listed in neitherkeysnorgroupsare added as one more group, with a message.- ...
Passed to each table's print method, e.g.
print_engine = "data.frame".- visible
(
scalar logical)
Whether the value was visible.
Value
A list of ltsummary tables with class "ltsummary_split" (also
"tbl_split"). Chained splits return a single flat list.
See also
Other stack and merge:
tbl_merge(),
tbl_stack(),
tbl_strata(),
tbl_strata_nested_stack()
Examples
tbl <- trial |>
tbl_summary(by = trt, include = c(age, grade), missing = "no")
# Example 1 ----------------------------------
# one table per variable
tbl_split_by_rows(tbl, variables = age)
# Example 2 ----------------------------------
# split the statistic columns apart, repeating the label column
tbl_split_by_columns(tbl, groups = list("stat_1", "stat_2"))