Aggregate function in R with multiple function arguments
问题 I have sample data.set containing climate data for different seasons: df <- data.frame(season=rep(1:5,2),year=rep(1:2,each=5), temp=c(2,4,3,5,2,4,1,5,4,3),ppt=c(4,3,1,5,6,2,1,2,2,2), samples=c(22,25,24,31,31,29,28,31,30,32)) I can determine the mean of my climate variables for each season for each year simply: aggregate(df[,c('temp','ppt')], by = list(df$season,df$year), function(x) mean(x,na.rm=T)) However, I want to determine the weighted mean of each season|year combo using variable