Merges two or more ltsummary tables side by side, matching rows on the
merge_vars columns. Merging works best with like tables: the same
variables summarized the same way, as in regression models of the same
terms. The interface is that of gtsummary::tbl_merge().
Every column that is not a merge column is renamed with the table's
position (stat_1_1, estimate_2, ...), and each table's styling
follows its renamed columns. Rows of the first table come first, in
order; rows found only in a later table are appended, which can put them
out of order. Reorder them with modify_table_body() if needed.
Arguments
- tbls
(
list)
List of ltsummary tables.- tab_spanner
(
character)
Spanning headers placed over each table's columns, one per table. The strings are interpreted as markdown and the header statistics are available in braces, e.g."**N = {N}**". Default isNULL, which places"**Table 1**","**Table 2**", ...;FALSEplaces no spanning headers.- merge_vars
(
character)
Columns oftable_bodythe rows are matched on. Columns named here that are not present in every table are dropped. Default isNULL, which matches onvariable,row_type,var_labelandlabel(those present in the first table).- tbl_ids
(
character)
Optional names for the input tables, one per table, used to name thetblselement of the result.- quiet
(
scalar logical)
Whether to suppress the message warning of possible row-ordering problems when the tables are not alike. Default isFALSE.
See also
Other stack and merge:
tbl_split_by_rows(),
tbl_stack(),
tbl_strata(),
tbl_strata_nested_stack()
Other table builders:
tbl_continuous(),
tbl_cross(),
tbl_custom_summary(),
tbl_likert(),
tbl_regression(),
tbl_stack(),
tbl_strata(),
tbl_strata_nested_stack(),
tbl_summary(),
tbl_survfit(),
tbl_uvregression(),
tbl_wide_summary()
Examples
# Example 1 ----------------------------------
# two models of the same terms, side by side
t1 <- glm(response ~ trt + grade + age, trial, family = binomial) |>
tbl_regression(exponentiate = TRUE)
t2 <- glm(death ~ trt + grade + age, trial, family = binomial) |>
tbl_regression(exponentiate = TRUE)
tbl_merge(list(t1, t2), tab_spanner = c("**Tumor Response**", "**Death**"))
# Example 2 ----------------------------------
# summary statistics beside univariable models
t3 <- trial[c("age", "marker", "grade")] |>
tbl_summary(missing = "no") |>
add_n() |>
modify_header(stat_0 = "**Summary Statistics**")
t4 <- tbl_uvregression(trial[c("age", "marker", "grade")], method = lm,
y = age, hide_n = TRUE)
tbl_merge(list(t3, t4)) |>
remove_spanning_header(columns = everything())
#> The number rows in the tables to be merged do not match, which may result in rows appearing out of order.
#> ℹ See `tbl_merge()` help file for details. Use `quiet=TRUE` to silence message.