I would like to perform granular control of the number of decimal places for all statistics of each variable. In the reproducible example below, let's say I want to have the mean and median of "age" displayed with one decimal place and the mean and median of "marker" with 3 decimal places. I have been unable to achieve that. Any help would be much appreciated.
library(gtsummary)
trial %>% select(trt, age, marker) %>%
tbl_summary(by = trt,
missing = "no",
type = all_continuous() ~ "continuous2",
statistic = all_continuous() ~ c(
"{mean}",
"{median}"),
digits = list(all_continuous() ~ c(1, 3)))
CodePudding user response:
You could pass the desired number of digits for each variable like so:
library(gtsummary)
trial %>%
select(trt, age, marker) %>%
tbl_summary(by = trt,
missing = "no",
type = all_continuous() ~ "continuous2",
statistic = all_continuous() ~ c(
"{mean}",
"{median}"),
digits = list(age ~ 1, marker ~ 3))