library(dplyr)
data <- data.frame(
year = rep(c(2000, 2001, 2002), each = 12),
month = rep(1:12, times = 3),
value = sample(1:1000, 3*12)
)
data.from.march.to.july <- data[data$month %in% 3:7, ]
data.averages <- data.from.march.to.july %>%
group_by(year) %>%
summarise(avg = mean(value), .groups = "drop_last")