Skip to contents

Merge gtsummary tables, e.g. tbl_regression, tbl_uvregression, tbl_stack, tbl_summary, tbl_svysummary, etc.

Usage

tbl_merge(tbls, tab_spanner = NULL)

Arguments

tbls

(list)
List of gtsummary objects to merge

tab_spanner

(character)
Character vector specifying the spanning headers. Must be the same length as tbls. The strings are interpreted with gt::md. Must be same length as tbls argument. Default is NULL, and places a default spanning header. If FALSE, no header will be placed.

Value

A 'tbl_merge' object

Author

Daniel D. Sjoberg

Examples

# Example 1 ----------------------------------
# Side-by-side Regression Models
library(survival)

t1 <-
  glm(response ~ trt + grade + age, trial, family = binomial) %>%
  tbl_regression(exponentiate = TRUE)
t2 <-
  coxph(Surv(ttdeath, death) ~ trt + grade + age, trial) %>%
  tbl_regression(exponentiate = TRUE)

tbl_merge(
  tbls = list(t1, t2),
  tab_spanner = c("**Tumor Response**", "**Time to Death**")
)
Characteristic Tumor Response Time to Death
OR1 95% CI1 p-value HR1 95% CI1 p-value
Chemotherapy Treatment





    Drug A

    Drug B 1.13 0.60, 2.13 0.7 1.30 0.88, 1.92 0.2
Grade





    I

    II 0.85 0.39, 1.85 0.7 1.21 0.73, 1.99 0.5
    III 1.01 0.47, 2.15 >0.9 1.79 1.12, 2.86 0.014
Age 1.02 1.00, 1.04 0.10 1.01 0.99, 1.02 0.3
1 OR = Odds Ratio, CI = Confidence Interval, HR = Hazard Ratio
# Example 2 ---------------------------------- # Descriptive statistics alongside univariate regression, with no spanning header t3 <- trial[c("age", "grade", "response")] %>% tbl_summary(missing = "no") %>% add_n() %>% modify_header(stat_0 ~ "**Summary Statistics**") t4 <- tbl_uvregression( trial[c("ttdeath", "death", "age", "grade", "response")], method = coxph, y = Surv(ttdeath, death), exponentiate = TRUE, hide_n = TRUE ) tbl_merge(tbls = list(t3, t4)) %>% modify_spanning_header(everything() ~ NA_character_)
Characteristic N Summary Statistics1 HR2 95% CI2 p-value
Age 189 47 (38, 57) 1.01 0.99, 1.02 0.3
Grade 200



    I
68 (34%)
    II
68 (34%) 1.28 0.80, 2.05 0.3
    III
64 (32%) 1.69 1.07, 2.66 0.024
Tumor Response 193 61 (32%) 0.50 0.31, 0.78 0.003
1 Median (Q1, Q3); n (%)
2 HR = Hazard Ratio, CI = Confidence Interval