how to do conditional logic in gtsummary?

33 views Asked by At

I get this output

#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)

0

There are 0 answers