I would like to calculate a sample mean in R by introducing a specific criteria. For example I have this table and I want the means of only those for whom stage = 1 or 2:
treatment session period stage wage_accepted type
1 1 1 1 25 low
1 1 1 3 19 low
1 1 1 3 15 low
1 1 1 2 32 high
1 1 1 2 13 low
1 1 1 2 14 low
1 1 2 1 17 low
1 1 2 4 16 low
1 1 2 5 21 low
The desired out in this case should be:
stage mean
1 21.0
2 19.6667
Thanks in advance.