2016-04-21 60 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)) 
相關問題