求学校C作品Composition得分的平均数。
方法一
1.step 找出logical index vector
> library(MASS) # load the MASS package
> school = painters$School # the painter schools
> c_school = school == "C" # the logical index vector
2.step 找出school为C的行
> c_painters = painters[c_school, ]
3.step 计算平均数
> mean(c_painters$Composition)
[1] 13.167
方法二
直接用tapply,算出所有学校的Composition的分数平均数。
> tapply(painters$Composition, painters$School, mean)
A B C D E F G H
10.400 12.167 13.167 9.100 13.571 7.250 13.857 14.000
http://www.r-tutor.com/elementary-statistics/qualitative-data/category-statistics


雷达卡



京公网安备 11010802022788号







