'Selecting columns based on aggregation in r
I have a dataframe with the following 5 character variables (Publisher, Platform, Genre, Rating, Global Sales), i would like to fliter it to get the top 30 Publishers based on their global sales, so in the end, i would like to have a table with 4 variables and 30 records ( Publisher (top 30), Platform, Genre, Rating).
Solution 1:[1]
using {dplyr} and the pipe operator for convenience and legibility:
df %>%
slice_max(`Global Sales`, n=30) %>%
select(-`Global Sales`)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | I_O |
