1、224Cheryl Cushing57566185Reuven Ytzrhak45496156Joel Knox63489307Mary Rayburn576378Greg England421569Brad Tmac5996810Tracy Mcgrady666100381:输入数据R语言导入xlsxinstall.packages(xlsx)library(xlsx)workbook-D:/R /StuScore.xlsx Math Science English 84.7 15.1 9.53:通过函数mean()来计算各行的均值以及获得综合得分,并使用cbind()将其添加到花名册中 #
2、3在afterscale中计算标准差均值,并将其添加到StuScore score-apply(afterscale,1,mean)#1表示行,mean表示均值函数 StuScore afterquantile=afterquantile1A StuScore$gradescore=afterquantile2Bafterquantile2&=afterquantile3Cafterquantile3&=afterquantile4Dafterquantile4E StuId StuName Math Science English score grade1 1 John Davis 502
3、95 25 0.22 B2 2 Angela Williams 465 67 12 -1.00 E3 3 Bull Jones 621 78 22 0.21 B4 4 Cheryl Cushing 575 66 18 -0.38 E5 5 Reuven Ytzrhak 454 96 15 -0.30 E6 6 Joel Knox 634 89 30 0.78 B7 7 Mary Rayburn 576 78 37 0.56 B8 8 Greg England 421 56 12 -1.42 E9 9 Brad Tmac 599 68 22 -0.10 E10 10 Tracy Mcgrady
4、666 100 38 1.43 B6:使用strsplit()以空格为界把学生姓名拆分为姓氏和名字 StuScore$StuName-as.character(StuScore$StuName) is.character(StuScore$StuName)1 TRUE name-strsplit(StuScore$StuName, name11 JohnDavis2AngelaWilliams3BullJones4CherylCushing5ReuvenYtzrhak6JoelKnox7MaryRayburn8GregEngland 9BradTmac10TracyMcgrady7:把name
5、分成Firstname和LastName,加入到StuScore中 FirstName-sapply(name,1) LastName,2)-cbind(FirstName,LastName,StuScore,-1) FirstName LastName LastName StuName Math Science English score grade1 John Davis Davis John Davis 502 95 25 0.22 B2 Angela Williams Williams Angela Williams 465 67 12 -1.00 E3 Bull Jones Jone
6、s Bull Jones 621 78 22 0.21 B4 Cheryl Cushing Cushing Cheryl Cushing 575 66 18 -0.38 E5 Reuven Ytzrhak Ytzrhak Reuven Ytzrhak 454 96 15 -0.30 E6 Joel Knox Knox Joel Knox 634 89 30 0.78 B7 Mary Rayburn Rayburn Mary Rayburn 576 78 37 0.56 B8 Greg England England Greg England 421 56 12 -1.42 E9 Brad Tm
7、ac Tmac Brad Tmac 599 68 22 -0.10 E10 Tracy Mcgrady Mcgrady Tracy Mcgrady 666 100 38 1.43 B8:order排序 StuScoreorder(LastName,FirstName),1 John Davis Davis John Davis 502 95 25 0.22 B8 Greg England England Greg England 421 56 12 -1.42 E6 Joel Knox Knox Joel Knox 634 89 30 0.78 B7 Mary Rayburn Rayburn
8、Mary Rayburn 576 78 37 0.56 B9 Brad Tmac Tmac Brad Tmac 599 68 22 -0.10 E2 Angela Williams Williams Angela Williams 465 67 12 -1.00 E9:为StuScore绘制分组条形图vcdlibrary(vcd)fill_colors-c() #不同的等级,不同的颜色显示for(i in 1:length(StuScore$Science)if(StuScore$Sciencei=100) fill_colors-c(fill_colors,redelse if(StuSco
9、re$Sciencei=80)yellow 80&=60)blue elsegreen barplot(StuScore$Science, #条形图 main=Science Score, xlab=Name,ylab=ScienceScore col=fill_colors, names.arg=(paste(substr(FirstName,1,1),.,LastName), #设定横坐标名称 border=NA, #条形框不设置边界线 font.main=4, font.lab=3, beside=TRUE) legend(x=8.8,y=100, #左上角点的坐标 cex=.8, #缩放比例 inset=5, c(Excellent,GoodOrdinaryBad), pch=c(15,16,17,19), #图例中的符号 col=c(), bg=#821122, #背景色 xpd=TRUE, #可以在绘图区之外显示 tex
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1