我也想用 ddply 或聚合来逐列总结,我知道该怎么做……但是,我还想在我的分组变量中添加组,以自定义方式总结数据,见下文:
##Create Data
year<-c(2008,2008,2008,2008,2009,2009,2009,2010,2010,2010,2010,2011,2011,2011,2011,2011)
catch<-c(1,2,0,1,1,0,1,0,1,2,1,0,1,1,1,0)
df<-data.frame(year,catch)
##I know how to aggregate by year:
yearlyAVcap<-ddply(df,~year,summarise,mean=mean(catch),sd=sd(catch))
##But I'd like to have 2008,2009,2010 summarized together and 2011 on it's own (i,e two groups- 1=2008,2009,2010 ; 2=2011)