1

I'd like to modify, in tbl_summary "Median (IQR)" by "median [Q1 : Q3]", and "Range" by "Min -Max" ?

I'd like that in the far left colomn, we'd read "median [Q1 : Q3]" instead of "Median (IQR)"

trial %>% select(trt, age) %>% 
tbl_summary(by = trt,
 type = list(all_continuous()  ~ "continuous2",
  all_categorical() ~ "categorical"),
    statistic = list(all_continuous()~ c("{N_nonmiss}",
                                        "{min} - {max}", 
                                        "{mean} ({sd})",
                                        "{median} [{p25} - {p75}]")))
marina
  • 26
  • 3

1 Answers1

2

You can use the add_stat_label() function from the same package.

library(gtsummary)
trial |> 
  select(trt, age) |> 
  tbl_summary(by = trt,
              type = list(all_continuous()  ~ "continuous2",
                          all_categorical() ~ "categorical"),
              statistic = list(all_continuous() ~ c("{N_nonmiss}",
                                                    "{min} - {max}",
                                                    "{mean} ({sd})",
                                                    "{median} [{p25} - {p75}]"))) |> 
  add_stat_label(label = list(all_continuous() ~ c("N",
                                                   "Min - Max",
                                                   "Mean (SD)",
                                                   "Median [Q1 : Q3]")))

See the documentation for more info.

Andrea M
  • 2,314
  • 1
  • 9
  • 27
  • That's for "footnotes", not for the table, right ? – marina Apr 20 '22 at 09:37
  • 1
    Can you edit your question to make it reproducible? As in, adding sample data (in code format) and the code that you've used so far. [more info](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Andrea M Apr 20 '22 at 09:41
  • 1
    And your expected output. It's not clear what do you mean with "for the table". – Andrea M Apr 20 '22 at 09:43
  • I edited my post for the table I meant the output, in particular I want to modify the far left column – marina Apr 20 '22 at 09:56
  • I am sorry, Andrea M, I do not see what is wrong in my question. – marina Apr 20 '22 at 10:10
  • Thanks for editing, it's clear now. I've updated my answer. – Andrea M Apr 20 '22 at 10:45