Skip to content

Instantly share code, notes, and snippets.

@ddsjoberg
Created June 9, 2021 15:29
Show Gist options
  • Save ddsjoberg/fbb64c4ee1ead7e77abb5436e5e43472 to your computer and use it in GitHub Desktop.
Save ddsjoberg/fbb64c4ee1ead7e77abb5436e5e43472 to your computer and use it in GitHub Desktop.
library(gtsummary)
library(tidyverse)
trial %>%
tbl_strata(
strata = trt,
~ .x %>%
nest(data = -grade) %>%
arrange(grade) %>%
rowwise() %>%
mutate(
# within Grade, summarize tumor response
tbl =
tbl_summary(data,
include = response,
missing = "no",
statistic = response ~ "{p}% ({n}/{N})",
label = list("response" = paste("Grade", as.character(grade)))) %>%
list()
) %>%
# stack the tbls within each grade into a single tbl
pull(tbl) %>%
tbl_stack()
) %>%
# remove default spanning header and footnote
modify_spanning_header(everything() ~ NA) %>%
modify_footnote(everything() ~ NA) %>%
# update the column headers and add a table title
modify_header(stat_0_1 = "Drug A", stat_0_2 = "Drug B", label = "") %>%
modify_caption("Tumor Response Rate by Treatment and Grade")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment