【发布时间】:2015-06-16 16:50:28
【问题描述】:
这是获取示例数据集的代码:
set.seed(0)
practice <- matrix(sample(1:100, 20), ncol = 2)
data <- as.data.frame(practice)
data <- cbind( lob = sprintf("objective%d", rep(1:2,each=5)), data)
data <- cbind( student = sprintf("student%d", rep(1:5,2)), data)
names(data) <- c("student", "learning objective","attempt", "score")
data[-8,]
数据如下:
student learning objective attempt score
1 student1 objective1 90 6
2 student2 objective1 27 19
3 student3 objective1 37 16
4 student4 objective1 56 60
5 student5 objective1 88 34
6 student1 objective2 20 66
7 student2 objective2 85 42
9 student4 objective2 61 82
10 student5 objective2 58 31
我想要的是:
student objective1 objective2
attempt score attempt score
1 student1 90 6 20 66
2 student2 27 19 85 42
3 student3 ... 0 0
4 student4 ... ...
5 student5 ... ...
有70个学习目标,所以复制粘贴尝试和分数会很繁琐,所以我想知道是否有更好的方法来清理数据。
R:我尝试使用 R 中的 melt 函数来获取新数据,但效果不佳。部分学生的分数缺失且学生姓名未列出,例如本例中为student3,所以我不能只cbind 分数。
Excel:有 70 个学习目标,由于缺少名称,我必须检查所有这 70 个目标的所有对应行 VLOOKUP:
(=VLOOKUP($C7,'0learning.csv'!$B$372:$G$395,5,0)
(=VLOOKUP($C7,'0learning.csv'!$B$372:$G$395,6,0)
有没有更好的办法?
【问题讨论】: