匯總/匯總每組的多個(gè)變量(例如總和,平均值)從數(shù)據(jù)幀,是否有聚集(一個(gè)簡(jiǎn)單的方法sum,mean,max同時(shí)等c)中多個(gè)變量?以下是一些示例數(shù)據(jù):library(lubridate)days = 365*2date = seq(as.Date("2000-01-01"), length = days, by = "day")year = year(date)month = month(date)x1 = cumsum(rnorm(days, 0.05)) x2 = cumsum(rnorm(days, 0.05))df1 = data.frame(date, year, month, x1, x2)我想同時(shí)按年和月匯總數(shù)據(jù)框中的變量x1和x2變量df2。以下代碼聚合x(chóng)1變量,但是是否也可以同時(shí)聚合x(chóng)2變量?### aggregate variables by year monthdf2=aggregate(x1 ~ year+month, data=df1, sum, na.rm=TRUE)head(df2)任何建議將不勝感激。
匯總/匯總每組的多個(gè)變量(例如總和,平均值)
BIG陽(yáng)
2019-05-24 14:46:56