3
classlist = read.table("classlist.txt", sep="\t", header=T)
classlist
Testscore <- runif(35,60,100)
classlist$Testscore <- Testscore
classlist
classlist$Grade <- function(Testscore) {
if(Testscore>=95){
grade = "A"`enter code here`
} else if(Testscore>=90 & Testscore<95){
grade = "A-"
} else if(Testscore>=85 & Testscore<90){
grade = "B+"
} else if(Testscore>=80 & Testscore<85){
grade = "B"
} else if(Testscore>=75 & Testscore<80){
grade = "B-"
} else {grade = "C"}
}
我要分配相應的等級在表中的列級有進口 當我嘗試此代碼提到了以下錯誤:分配字母等級來testscores在一個表中的R
Error in rep(value, length.out = nrows) :
attempt to replicate an object of type 'closure'
文檔這可以幫助你 http://stackoverflow.com/questions/17685502/in-r-getting-the-following-error-attempt-to-replicate-an-object-of- type-clos – Ars
您正在爲'classlist $ Grade'分配一個函數。爲了你的代碼的工作,你應該首先創建函數myfunc < - function(Testscore){...}'然後應用它'classlist $ Grade < - myfunc(classlist $ Testscore)' – scoa