I have a large data frame that looks similar to this:
df <- data.frame(dive = factor(sample(c("dive1","dive2"), 10, replace=TRUE)),
Adding alternative base R approach, which remains fast under various cases.
rowsummean <- function(df) { rowsum(df$speed, df$dive) / tabulate(df$dive) }
Borrowing the benchmarks from @Ari:
10 rows, 2 groups
10 million rows, 10 groups
10 million rows, 1000 groups