I have output from a survey and the responses from each person are in one long row. Questions are labeled with a prefix of Q1, Q2, Q3 of varying lengths depending on the number of answer options.
I would like to create graphs and summarize results by question in R but struggling to find a way to identify the different prefixes.
I tried this
data2 <- adply(data[grepl("Q", colnames(data))],2, function(x)
data.frame(Count=as.data.frame(table(x))[2,2],
Perc=as.data.frame(prop.table(table(x)))[2,2]))`
But that just gave me each column as a row with the count and percentage. That is the closest I have gotten to what I want.