I have a dataframe competition with columns branch, phone and sales
| branch | phone | sales|
|----------|---------|------|
| 123 | milky | 654 |
| 456 | lemon | 342 |
| 789 | blue | 966 |
| 456 | blue | 100 |
| 456 | milky | 234 |
| 123 | lemon | 874 |
| 789 | milky | 234 |
| 123 | blue | 332 |
| 789 | lemon | 865 |
I want to show the highest number of sales for every phone:
The output should be a dataframe winners that look like this
| branch | phone | sales|
|----------|---------|------|
| 123 | milky | 654 |
| 789 | blue | 966 |
| 123 | lemon | 874 |
I tried order a dataframe by sales first, and then left only 3 top rows,
competition <- competition[order(competition$sales, decreasing = TRUE ),]
winners <- head(competition, 3)
But the output shows lemon phone two times with 874 and 865 sales