R語言中aggregate?函數(shù)詳解
R語言中aggregate 函數(shù)
aggregate函數(shù)是數(shù)據(jù)處理中常用到的函數(shù),具有強(qiáng)大的功能??梢园凑找蟀褦?shù)據(jù)打組聚合,然后對聚合以后的數(shù)據(jù)進(jìn)行加和、求平均等各種操作。具體說明可使用命令:help("aggregate")獲取官方文檔。
001、測試數(shù)據(jù)框
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、 調(diào)用函數(shù)
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)
到此這篇關(guān)于R語言中aggregate 函數(shù)詳解的文章就介紹到這了,更多相關(guān)R語言aggregate 函數(shù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
使用R語言繪制3D數(shù)據(jù)可視化scatter散點(diǎn)圖實現(xiàn)步驟
這篇文章主要為大家介紹了使用R語言繪制3D數(shù)據(jù)可視化scatter散點(diǎn)圖的實現(xiàn)步驟,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步2022-02-02R語言學(xué)習(xí)Rcpp基礎(chǔ)知識全面整理
這篇文章主要介紹了R語言學(xué)習(xí)Rcpp知識的全面整理,包括相關(guān)配置說明,常用數(shù)據(jù)類型及建立等基礎(chǔ)知識的全面詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助2021-11-11