I'm working with surveys where if a specific answer is provided, a follow-up question is given. For example, if the answer to q1 is "yes" then q2 is asked. However, if I add both questions to the same table, the Unknown count for q2 is 5 but should be 0. Unfortunately, I do have missing data and want to show that. How do I only show the q2 Unknown count for those who have q1=="yes" & q2==NA?
library(tidyverse)
library(knitr)
library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.6.0'
tibble::tribble(
~q1, ~q2,
"yes", "yes",
"yes", "yes",
"yes", "no",
"yes", "no",
"yes", "no",
"no", NA,
"no", NA,
"no", NA,
"no", NA,
"no", NA
) %>% tbl_summary() %>% as_kable()
| Characteristic | N = 10 |
|---|---|
| q1 | 5 (50%) |
| q2 | 2 (40%) |
| Unknown | 5 |
Created on 2022-05-06 by the reprex package (v2.0.1)
