001、测试数据框
studentID <- seq(1, 20) gender <- rep(c("M", "M", "F", "F", "F"), 4) math <- rep(c(92, 86, 85, 74, 82), 4) english <- rep(c(76, 69, 82, 71, 80), 4) class <- rep(c(paste0(c(1, 2, 2, 1),"班")), 5) score <- data.frame(studentID, class, gender, math, english) dim(score) head(score
002、 调用函数
aggregate(score[,5], by=list(score$gender), mean) aggregate(score[,5], by=list(score$gender, score$class), mean) aggregate(score[,5], by=list(score$gender, score$class), sum) aggregate(score[,5], by=list(score$gender, score$class), max)
来源:https://blog.csdn.net/chongbaikaishi/article/details/116131517
标签:函数,gender,list,score,aggregate,mean,class,语言 From: https://www.cnblogs.com/liujiaxin2018/p/17354763.html