Appends two or more ltsummary tables on top of each other. The columns of
the result are the union of the input columns, matched by name, and every
styling instruction of every input is kept: a hidden tbl_id1 column
records which table each row came from, and the stored row selectors are
scoped to it. Stacking tables that are themselves stacked adds tbl_id2
outside tbl_id1, and so on. The interface is that of
gtsummary::tbl_stack().
With group_header, each table is labelled with a full-width group row.
The group column renders as lt separator rows, and as.data.frame()
shows the label on the first row of each group. bold_labels() and
friends keep targeting the label column of the stacked table, not the
group rows.
Header labels are taken from the first table that has them; use
attr_order to give a later table precedence. The attributes a table can
hold only one of, its caption and its horizontal rule, always come from
the first table in tbls that has them.
Usage
tbl_stack(
tbls,
group_header = NULL,
quiet = FALSE,
attr_order = seq_along(tbls),
tbl_ids = NULL,
tbl_id_lbls = NULL
)Arguments
- tbls
(
list)
List of ltsummary tables.- group_header
(
character)
Header placed above each table's rows, one per table. Default isNULL, for no group rows.- quiet
(
scalar logical)
Whether to suppress the message listing the column headers when they differ between the tables. Default isFALSE.- attr_order
(
integer)
The order in which the tables' header labels take precedence.attr_order = 2uses the headers of the second table. Default is the order oftbls.- tbl_ids
(
character)
Optional names for the input tables, one per table, used to name thetblselement of the result.- tbl_id_lbls
(
vector)
Optional labels, one per table, stored in a hiddentbl_id1_lblcolumn of the result'stable_body. Mostly for the development of other functions.
See also
Other stack and merge:
tbl_merge(),
tbl_split_by_rows(),
tbl_strata(),
tbl_strata_nested_stack()
Other table builders:
tbl_continuous(),
tbl_cross(),
tbl_custom_summary(),
tbl_likert(),
tbl_merge(),
tbl_regression(),
tbl_strata(),
tbl_strata_nested_stack(),
tbl_summary(),
tbl_survfit(),
tbl_uvregression(),
tbl_wide_summary()
Examples
# Example 1 ----------------------------------
# an unadjusted and an adjusted model of the same term
t1 <- glm(response ~ trt, trial, family = binomial) |>
tbl_regression(exponentiate = TRUE, label = list(trt = "Treatment (unadjusted)"))
t2 <- glm(response ~ trt + grade + stage + marker, trial, family = binomial) |>
tbl_regression(include = trt, exponentiate = TRUE, label = list(trt = "Treatment (adjusted)"))
tbl_stack(list(t1, t2))
# Example 2 ----------------------------------
# group headers label the two models
t3 <- glm(death ~ trt, trial, family = binomial) |>
tbl_regression(exponentiate = TRUE)
tbl_stack(list(t1, t3), group_header = c("Tumor Response", "Death"))