成绩的处理
#設置小數點后位數
options(digits=2)
name=c("John Davis","Angela Williams","Bullwinkle Moose","David Jones","Janice Markhammer","Cheryl Cushing","Reuven Ytzrhak","Greg Knox","Joel England","Mary Rayburn")
math=c(502,600,412,358,495,512,410,625,573,522)
eng=c(25,22,18,15,20,28,15,30,27,18)
sci=c(95,99,80,82,75,85,80,95,89,86)
scoreData=data.frame(name,math,sci,eng,stringsAsFactors=FALSE)
#成績的標準化
x=scale(scoreData[,2:4])
#求平均
score=apply(x,1,mean)
scoreData=cbind(scoreData,score)
y=quantile(score,c(0.8,0.6,0.4,0.2))
#評等級
scoreData$grade[score>=y[1]]="A"
scoreData$grade[score<y[1]&score>=y[2]]="B"
scoreData$grade[score<y[2]&score>=y[3]]="C"
scoreData$grade[score<y[3]&score>=y[4]]="D"
scoreData$grade[score<y[4]]="F"
nametemp=strsplit(scoreData$name," ")
lastname=sapply(nametemp,"[",2)
fristname=sapply(nametemp,"[",1)
scoreData=cbind(fristname,lastname,scoreData[-1])
scoreData=scoreData[order(lastname,fristname),]
最終scoreData為:
轉載于:https://www.cnblogs.com/sklww/p/3519680.html
總結
- 上一篇: (转)永磁同步电机工作原理(https:
- 下一篇: MIT协议原文