For dichtomous variables, the tbl_summary()
function provides the option to display only one category by using the type
argument. The following code provides the solution. It correctly considers the total N.
library(gtsummary)
d<-tibble::tribble(
~Gender, ~Treatment,
"Male", "A",
"Male", "B",
"Female", "A",
"Male", "C",
"Female", "B",
"Female", "C")
d %>% tbl_summary(
by = Treatment,
# declare Gender as dichotomous variable
type = list(Gender ~ 'dichotomous'),
# set the value to show
value = list(Gender ~ 'Female'),
# by default as characteristic still "Gender" is shown, change to "Female"
label = list(Gender ~ 'Female'))
The output: