A seemingly straightforward task has proven to be really difficult in R. I'm working with survey data containing propositions asking respondents to indicate their level of agreement or disagreement on a 7-point Likert Scale. I'm trying to create frequency tables (see Table 1 below) that show the proportion of respondents in each sex/age group category that selected strongly agreed, slightly agreed, agreed, neutral, etc., in response to each proposition.
How can I create Table 1 from Table 2 (this is the way my current dataframe is setup in R)? In Table 2, the columns headed Q31, Q32, Q33, and Q34 are each separate propositions and the values in the cells are numerical codes for the 7 options on the Likert scale.
Table 1
| Sex | Age Group | Question | Strongly Agree |
|---|---|---|---|
| 1 | 30 - 39 | 31 | 0.21 |
| 2 | 30 - 39 | 31 | 0.48 |
| 1 | 40 - 49 | 31 | 0.12 |
| 2 | 40 - 49 | 31 | 0.65 |
Table 2
| Sex | Age Group | Q31 | Q32 | Q33 | Q34 |
|---|---|---|---|---|---|
| 1 | 30 - 39 | 1 | 7 | 1 | 5 |
| 2 | 30 - 39 | 3 | 5 | 2 | 6 |
| 1 | 40 - 49 | 4 | 6 | 3 | 2 |
| 2 | 40 - 49 | 2 | 2 | 4 | 2 |
Open to any suggestions, as I've been banging my head against this for too long! Thanks!