I want to create some mean of sepal.length, but divided by species. Using mosaic
package
mean(Sepal.Length~Species)
It didn't work
I want to create some mean of sepal.length, but divided by species. Using mosaic
package
mean(Sepal.Length~Species)
It didn't work
We need to specify the data
mosaic::mean(Sepal.Length ~ Species, data = iris)
# setosa versicolor virginica
# 5.006 5.936 6.588
Using dplyr
, you can do:
library(dplyr)
iris %>% group_by(Species) %>% summarise(Mean = mean(Sepal.Length))
# A tibble: 3 x 2
Species Mean
<fct> <dbl>
1 setosa 5.01
2 versicolor 5.94
3 virginica 6.59
A base R solution
aggregate(Sepal.Length ~ Species, data=iris, mean)
Species Sepal.Length
1 setosa 5.006
2 versicolor 5.936
3 virginica 6.588