Hi,
I have this nultiresponse df. TMC is one question with 4 answer options:
source <- data.frame(
stringsAsFactors = FALSE,
URN = c("21GB01293040","21GB01240221",
"21GB03294610","21GB01309069","21GB03078286",
"21GB01086060","21GB01169525","21GB01209144",
"21GB01204925","21GB90063865",
"21GB01068838","21GB01176411","21GB01215531"),
TMC.Communication = c(0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1),
TMC.Paperwork = c(0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0),
TMC.Electric = c(0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0),
TMC.Other = c(1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0),
Qtr = c(2021.5,2021.5,2021.5,2021.5,2021.25,
2021.25,2021.5,2021.5,2021.5,2021.5,
2021.25,2021.25,2021.5),
QA1 = c(9, 1, 8, 4, 8, 6, 7, 6, 2, 3, 6, 10, 8),
QA31 = c(7, 1, 8, 3, 8, 8, 8, 6, 2, 2, 7, 8, 8)
)
I can calculate counts and proportions for this question (overall and by Qtr):
library(dplyr)
library(tidyr)
idea <- source %>%
select(starts_with("TMC.")) %>%
summarise_all(list(Count = sum, Proportion = mean)) %>%
pivot_longer(everything(), names_to = c("Category", "summary"), names_sep = "_", "value") %>%
pivot_wider(names_from = summary, values_from = value)
idea2 <- source %>%
select(Qtr, starts_with("TMC.")) %>%
group_by(Qtr) %>%
summarise_all(list(Count = sum, Proportion = mean)) %>%
pivot_longer(-Qtr, names_to = c("Category", "summary"), names_sep = "_", "value") %>%
pivot_wider(names_from = summary, values_from = value)
Now I would like to show Mean scores of questions starting from QA instead of proportions. Is it possible?