A data frame or table has several columns as conditions and the rest as results, now I want to summary the table by the same conditions. That means, the results columns of the rows with same conditions will be added together.
- Using tapply()
1tapply(df$dt, df$group, summary) - Using
plyr
package
1ddply(df, .(group), summarise, mean=mean(dt), sum=sum(dt))
Reference:
http://stackoverflow.com/questions/9847054/how-to-get-summary-statistics-by-group
http://www.sr.bham.ac.uk/~ajrs/R/r-show_data.html
http://www.psychwire.co.uk/2011/04/aggregate-function-in-r-making-your-life-easier-one-mean-at-a-time/
http://www.psychwire.co.uk/2011/04/data-aggregation-in-r-plyr-sqldf-and-data-table/