I am attempting to add row totals to my tbl_summary()
.
Here is my code so far
ibrary(tidyverse)
library(gtsummary)
set.seed(42)
n <- 1000
dat <- data.frame(q=runif(n, min=45, max=85),
r=runif(n, min=2.4, max=6.0),
s=runif(n, min=24, max=60),
t=runif(n, min=0.28, max=1.73),
time=1)
patient <- data.frame(id=1:n,
treat = factor(sample(c('Treat','Control'), n, rep=TRUE, prob=c(.5, .5))),
age=sample(18:80, n, replace=TRUE),
sex = factor(sample(c('Male','Female'), n, rep=TRUE, prob=c(.6, .4))),
smoke=factor(sample(c("Never", 'Former', 'Current'), n, rep=TRUE, prob=c(.25, .6, .15))),
bmi=runif(n, min=16, max=45))
df <- cbind(patient, dat)
df %>% select(q, treat, smoke) %>%
tbl_continuous(variable = q,
by = treat,
include = smoke) %>% add_n()
Is anyone able to assist with this last step. I think my issue is where to place the add_n()
call. I have been using previously made gt_summary
tables for guidance but something is not working this time.
Much appreciated everyone :)