I would like to make a contingency table using the vcd package structable function. Two of my selected columns (consent_a
and consent_b
) has NA values as well as factor (Yes, No) values, because each case can be consented for procedure a OR procedure b, but not both. For instance if a case is consented for procedure a, they are not asked for procedure b (and thus consent_b
would be NA). In the contingency table, I want to include all cases where factor is yes, no, and NA.
library(vcd)
mydata <- data.frame(
report_year = c(2013, 2013, 2013, 2013, 2013, 2014, 2014, 2014, 2014, 2014),
report_week = c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2),
consenta = c("Yes", "Yes", NA, "Yes", "No", "Yes", "Yes", NA, "Yes", "No"),
consentb = c(NA, NA, NA, NA, "Yes", NA, NA, "Yes", NA, "No"))
epicurve <- as.data.frame(structable(proj11[, c("report_epiweek", "report_year", "consent_a", "consent_b")]))