Here is an example for you using the builtin iris dataset
library(tidyverse)
# mean of all Petal.Length (samples from 3 species mixed together)
mean(iris$Petal.Length)
# unique species are
unique(iris$Species)
# mean for filter for species setosa
mean(filter(iris, Species == "setosa")$Petal.Length)
# same again , is this nicer syntax ?---
# mean of all Petal.Length (samples from 3 species mixed together)
mean(iris %>% pull(Petal.Length))
# unique species are
unique(iris %>% pull(Species))
# mean for filter for species setosa
mean(iris %>%
filter(Species == "setosa") %>%
pull(Petal.Length))