1

I would like to have an overall column in this stratified table. Is it possible using tbl_strata oder do I need to make two tables and merge them?

trial |>
    select(age, grade, stage, trt) |>
    mutate(grade = paste("Grade", grade)) |>
    tbl_strata(
        strata = grade,
        .tbl_fun =
            ~ .x |>
            tbl_summary(by = trt, missing = "no"),
        .header = "**{strata}**, N = {n}"
    )

1 Answer 1

3

Sure, you create the stratified table as above, then merge it with an unstratified table. Example below!

library(gtsummary)

# create a table by Grade
tbl_by_grade <- trial |>
  select(age, grade, stage, trt) |>
  mutate(grade = paste("Grade", grade)) |>
  tbl_strata(
    strata = grade,
    .tbl_fun =
      ~ .x |>
      tbl_summary(by = trt, include = stage),
    .header = "**{strata}**, N = {n}"
  )

# create a table using all grades
tbl_all_grades <-
  trial |>
  tbl_summary(by = trt, include = stage) |> 
  modify_spanning_header(all_stat_cols() ~ "**All Grades**, N = {N}")

# merge the two tables together
tbl_final <- list(tbl_by_grade, tbl_all_grades) |> 
  tbl_merge(tab_spanner = FALSE)

enter image description here Created on 2025-01-22 with reprex v2.1.1

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.