2016-04-21 85 views
3

我认为有一行代码可以评定学生的答案,但我无法完全找到答案。这里有三个问题和两个学生的例子。评分学生的考试

在此先感谢

#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 
+0

如果你教CS,你可能会对https://cseducators.stackexchange.com/感兴趣(但由于它仍处于私人测试版,所以通过https://area51.stackexchange.com/proposals/92460/computer-science-educators进行最简单的输入) –

回答

8

我会做这种方式:responses == key[col(responses)]

+0

那是光滑的+1 –

1

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

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