Hello everyone!
Suppose that I have a dataset containing the information of 10 students and their grades. So the data look something like this:
Student | Grade |
---|---|
1 | 76 |
2 | 99 |
3 | 97 |
4 | 65 |
5 | 86 |
6 | 84 |
7 | 52 |
8 | 55 |
9 | 69 |
10 | 72 |
I wanna add another column (using mutate maybe?) called "Rank." And this rank will be based on students' grades. That is,
The first two students with the highest grades will be ranked 1
The three students with the next highest grades will be ranked 2
The three students with the next highest grades will be ranked 3
The rest will be ranked 4.
So ultimately, I wanna create something like this:
Student | Grade | Rank |
---|---|---|
1 | 76 | 2 |
2 | 99 | 1 |
3 | 97 | 1 |
4 | 65 | 3 |
5 | 86 | 2 |
6 | 84 | 2 |
7 | 52 | 4 |
8 | 55 | 4 |
9 | 69 | 3 |
10 | 72 | 3 |
Note that the example that I gave would be easier doing it by hand since there are only 10 students. But the actual dataset that I'll be using will have over 100 observations. And the ranking will be something like: The first 11 students with the highest grades will be ranked 1, the 33 students with the next highest grades will be ranked 2nd, etc.
Thank you!