从调查数据中获取比例表

时间:2019-05-08 18:10:26

标签: r

我有5点李克特量表(强烈同意,非常不同意)的30多个问题的调查数据

以下是一些示例数据:

survey_df <- data.frame("ID" = c(1,2,3,4,5),
                        "Q1" = c("Strongly Agree", "Strongly Agree", "Agree", "Agree", "Neither"),
                        "Q2" = c("Agree", "Strongly Disagree", "Disagree", "Agree", "Neither"),
                        "Q3" = c("Neither", "Neither", "Disagree", "Agree", "Neither"))

所以基本上我想从这里开始:

ID Q1             Q2                Q3
1  Strongly Agree Agree             Neither
2  Strongly Agree Strongly Disagree Neither
3  Agree          Disagree          Disagree
4  Agree          Agree             Agree
5  Neither        Neither           Neither

对此:

Question Strongly.Agree Agree Neither Disagree Strongly.Disagree N.Count
Q1       0.4            0.4   0.2     0.0      0.0               5
Q2       0.0            0.4   0.2     0.2      0.2               5
Q3       0.0            0.2   0.6     0.2      0.0               5

1 个答案:

答案 0 :(得分:2)

您需要使用librairie tidyr 中的函数gather()spread()来转置数据框,然后使用mutate()和{{1 }}(来自 dplyr )来计算mutate_at()和答案的比例。

N.Count