R语言中aggregate 函数详解

R语言中aggregate 函数 aggregate函数是数据处理中常用到的函数,具有强大的功能。可以按照要求把数据打组聚合,然后对聚合以后的数据进行加和、求平

R语言中aggregate 函数

aggregate函数是数据处理中常用到的函数,具有强大的功能。可以按照要求把数据打组聚合,然后对聚合以后的数据进行加和、求平均等各种操作。具体说明可使用命令:help("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)

到此这篇关于R语言中aggregate 函数详解的文章就介绍到这了,更多相关R语言aggregate 函数内容请搜索好代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持好代码网!

您可能有感兴趣的文章
R语言基本画图函数与多图多线的用法

R语言学习代码格式一键美化

R语言中循环的相关知识详解

R语言是什么 R语言简介

R语言控制结构知识点总结