#Creating the dataframe
data <- data.frame(
alive = c(1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1),
reason = c("", "", "", "", "", "", "pneumonia", "stillbirth", "", "", "", ""),
baby_ill = c(2, 2, 2, 1, 2, 1, 1, 1, 2, 2, 2, 1),
episode = c("", "", "", 3, "", 4, 4, "", "", "", "", "")
)
# Convert character columns to factors
data[] <- lapply(data, as.factor)
# Create gtsummary table
tbl_summary(data) %>% add_n()
[Desired output] (https://i.stack.imgur.com/l3ocg.png)