评分学生的考试

时间:2016-04-21 23:06:50

标签: r

我认为有一行代码可以评估我学生的答案,但我找不到它。这是一个有三个问题和两个学生的例子。

提前致谢

#the correct answers
key = t(c(1,2,3))

#the student responses
responses = t(data.frame(c(1,2,3),c(1,3,3)))
colnames(responses) =c('v1','v2','v3')
rownames(responses) = c('student1', 'student2')

#the desired graded matrix
graded = t(data.frame(c(T,T,T),c(T,F,T)))
dimnames(graded) = dimnames(responses)
graded

2 个答案:

答案 0 :(得分:8)

我这样做:responses == key[col(responses)]

答案 1 :(得分:1)

我看到它已经被回答了,哦,好吧:

t(apply(responses, 1, FUN = function(x) x == key))