小编San*_*afa的帖子

如何将逗号分隔的多个响应转换为 R 中的虚拟编码列

在一项调查中,有一个问题是“课程的哪个方面对您学习概念帮助最大?选择所有适用的”

以下是回复列表的样子:

Student_ID = c(1,2,3)
Responses = c("lectures,tutorials","tutorials,assignments,lectures", "assignments,presentations,tutorials")
Grades = c(1.1,1.2,1.3)
Data = data.frame(Student_ID,Responses,Grades);Data

Student_ID | Responses                           | Grades
1          | lectures,tutorials                  | 1.1
2          | tutorials,assignments,lectures      | 1.2
3          | assignments,presentations,tutorials | 1.3
Run Code Online (Sandbox Code Playgroud)

现在我想创建一个看起来像这样的数据框

Student_ID | Lectures | Tutorials | Assignments | Presentation | Grades
1          |     1    |     1     |      0      |       0      |  1.3
2          |     1    |     1     |      1      |       0      |  1.4
3          |     0    |     1     |      1      |       1      |  1.3 …
Run Code Online (Sandbox Code Playgroud)

r surveymonkey dummy-variable

0
推荐指数
1
解决办法
864
查看次数

标签 统计

dummy-variable ×1

r ×1

surveymonkey ×1