I have data from a questionaire where people had to score multiple questions on a 5 point scale. It resulted in a data frame that looks like this
Q5_1 <- c("completely agree", "agree a little", "completely agree", "completely agree")
Q5_2 <- c("agree a little", "do not agree or disagree", "agree a little", "completely agree"
Q5_3 <- c("do not agree or disagree","do not agree or disagree","do not agree or disagree","do not agree or disagree")
Now I want to make a frequency table that shows the values from two columns. And ideally also takes into account the possibilities that are never scored. so it would have to look like this
Q5_1 Q5_3
completely disagree 0 0
disagree a little 0 0
do not agree or disagree 0 4
agree a little 2 0
completely agree 2 0
I tried
table(df$Q5_1, df$Q5_3)
but this resulted in
do not agree or disagree
agree a little 2
completely agree 2
I do manage to get something that looks like the table i want but as a dataframe. But for the statistical testing i want to do i need it to be a (frequency) table
If we need the combinations that doesn't exist, convert the columns to
factorwithlevelsspecifiedOr we may use
countafter converting the columns tofactor