跳转到主内容
极星编程网:以代码为星,赴技术山海!

R语言中aggregate 函数详解

目录R语言中aggregate 函数

001、测试数据框

002、 调用函数

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语言之dplyr包常用函数方法示例学习R语言中set.seed()函数的作用详解R语言将变量分组的3种方法实例(含cut函数说明)

R语言which函数介绍及Rcpp改写详解R语言中merge函数详解R语言常用函数总结梳理(基本对象字符处理 数学 统计)

相关文章