I want to that the mean of one variable when two other variables are equal to a certain value. For example, I want to make a new data frame that has a variable called "mean", that gives the mean of all the values in S1 when year == 2003 and mon == 1, and then the next value of the mean of S1 values when year == 2003 and mon == 2.
YEAR MON S1 S
<dbl> <dbl> <dbl> <dbl>
1 2003 1 8.2 1.03
2 2003 1 7.39 0.97
3 2003 1 7.78 0.82
4 2003 2 7 0.91
5 2003 2 5 1.93
6 2003 2 5.49 0.31