R语言中aggregate 函数

 

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

 

posted @   小鲨鱼2018  阅读(233)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2022-04-26 linux 中调用shell脚本时指定工作目录为shell脚本所在的目录
2022-04-26 修改 WSL2 可用内存大小和交换分区大小
2022-04-26 linux 中 awk命令统计A、C、T、G碱基数目
2022-04-26 linux 中shell脚本统计参考基因组中碱基的总数目
2022-04-26 linux中如何将一行数据转换为一列数据
2022-04-26 linux中如何给数据添加行号
2021-04-26 linux系统中如何将一行数据转换为一列数据
点击右上角即可分享
微信分享提示