I have a large data frame that looks similar to this:
df <- data.frame(dive = factor(sample(c("dive1","dive2"), 10, replace=TRUE)),
We already have tons of options to get mean by group, adding one more from mosaic
package.
mosaic::mean(speed~dive, data = df)
#dive1 dive2
#0.579 0.440
This returns a named numeric vector, if needed a dataframe we can wrap it in stack
stack(mosaic::mean(speed~dive, data = df))
# values ind
#1 0.579 dive1
#2 0.440 dive2
data
set.seed(123)
df <- data.frame(dive=factor(sample(c("dive1","dive2"),10,replace=TRUE)),
speed=runif(10))