I have a dataframe containing responses to a multicode question by month, where:
The output I'm after is a contingency table (with %s) detailing the proportion of 1 ('Yes') responses by month for each of the multicode columns:
Example data:
| Month | Multicode_1| .... | Multicode_n|
| --- | .......... | .... | .......... |
| Jan22 | 1 | .... | .......... |
| Feb22 | 0 | .... | .......... |
Feels like this almost gets to it, but not quite:
ex8 <- NPSSurvey_df %>%
group_by(Month) %>% filter(Pack == "Sports", CustomerType == "New") %>%
summarise(across(Vid_Freeze:Mistake))
head(ex8)
Here an example with some simulated data, since the data is binary the mean
will be the same as the proportion of 1's.
library(dplyr)
data <-
data.frame(
month = sample(month.abb,100,replace = TRUE),
multicode1 = rbinom(100,1,.50),
multicode2 = rbinom(100,1,.15),
multicode3 = rbinom(100,1,.25),
multicode4 = rbinom(100,1,.85)
)
data %>%
group_by(month) %>%
summarise(across(.fns = ~100*mean(.,na.rm = TRUE)))