The ddply
function from plyr
always does a good job of this.
sumFrame <- plyr::ddply(df, "date", numcolwise(sum))
meanFrame <- plyr::ddply(df, "date", numcolwise(mean))
The first argument is the name of your data frame.
The second argument is the column it should group by - in this case it's date, but you can also give it a column vector with multiple columns names, e.g. c("date", "time")
.
The final argument takes what function you want to apply, in this case sum
and mean
. The numcolwise
bit is just to make sure the function applies this to the column, not a row.
As another note, as MrFlick said, you should be providing a reproducible example and some solutions you've tried so far.