R语言中aggregate函数进行整合数据

R语言中aggregate函数进行数据整合

1、

name <- rep(c("a","b","c"),3)
math <- 1:9
eng <- c(3,5,2,2,4,8,7,2,4)
chi <- c(3,4,8,5,9,4,7,5,6)
test <- data.frame(name, math, eng, chi)
test
a <- aggregate(test[,2:4], by=list(name = test$name),FUN = sum)
a
b <- aggregate(test[,2:4], by=list(name=test$name), FUN = mean)
b

原文地址:https://www.cnblogs.com/liujiaxin2018/p/14708433.html