I have a data frame of factors called questions
q1 q2 q3
A A B
C A A
A B C
That I want to reshape into
question answer freq
1 A 2
1 B 0
1 C 1
2 A 2
2 B 1
2 C 0
3 A 1
3 B 1
3 C 1
I feel like there should be a way to this with reshape2 or plyr, but I couldn't figure it out.
Instead, I did the following:
tbl <- data.frame()
for(i in 1:dim(questions)[2]){
subtable <- cbind(question = rep(i, 3),
as.data.frame(table(questions[i])))
tbl <- rbind(tbl, subtable)
}
Is there a cleaner approach to reshaping this table?