Reputation: 37
I've created a summary table with gtsummary. But I want to make some changes to the summary statistics. I would like the % to be a percentage of the total sum for each level, and not the entire variable. For grade 1 the total sum would be 68. So for drug A I want it to say 35(51.47%) (35/68x100). Similarly for drug B it would show 33(48.53%). How would I do that? Thanks a lot!
library(gtsummary)
data(trial)
trial2 <- trial %>% select(trt, grade)
trial2 %>%
tbl_summary(
by = trt,
statistic = list(all_categorical() ~ "{n} ({p}%)"))
Upvotes: 0
Views: 1213
Reputation: 174468
You can add percent = "row"
to your tbl_summary
call
trial2 %>%
tbl_summary(
by = trt,
statistic = list(all_categorical() ~ "{n} ({p}%)"),
percent = 'row')
Upvotes: 4