Home > database >  How can you add N to spanning header labels with gtsummary in R?
How can you add N to spanning header labels with gtsummary in R?

Time:12-14

I am working with the trial database and I wanted to add N after the Grades. I think N={n} needs to be added to modify_spanning_header but I dont know how to make that work.

Here is the code:


trial %>%
    select(trt, grade, age, stage) %>%
    mutate(grade = paste("Grade", grade)) %>%
    tbl_strata(
        strata = grade, 
        ~.x %>%
            tbl_summary(by = trt, missing = "no") %>%
            modify_header(all_stat_cols() ~ "**{level}**")
    )

CodePudding user response:

Example Below!

library(gtsummary)
packageVersion("gtsummary")

tbl <- 
  trial %>%
  select(trt, grade, age, stage) %>%
  mutate(grade = paste("Grade", grade)) %>%
  tbl_strata(
    strata = grade, 
    ~.x %>%
      tbl_summary(by = trt, missing = "no") %>%
      modify_header(all_stat_cols() ~ "**{level}**"),
    .header = "**{strata}** N={n}"
  )

enter image description here

  • Related