I'm trying to group the variables by their max values and then count the number of groups that have their max values in a certain period.
The data set looks like this:
Year | Car | Value |
---|---|---|
1991 | A | 21 |
1992 | A | 19 |
1993 | A | 20 |
1992 | B | 42 |
1993 | B | 17 |
1991 | C | 31 |
1992 | C | 50 |
1993 | C | 23 |
What I want to do is to find the max values per car and then count how many cars reached their maximum values per year.
So essentially, a table like this
Year | Count |
---|---|
1991 | 1 |
1992 | 2 |
1993 | 0 |
I was able to identify the max values per group using dplyr but cant figure out how to implement the count. Can someone please help? I've also tried top_n but that just gives me the max value per month which isnt what I want!