powered by
Extract rows belonging to top n groups of a certain column
keep_top_n(.data, col, n = 10)
The data frame to operate on
A formula indicating the column to group over
The number of top groups to extract
A data frame conaining only rows belonging to the top n groups of the column
# NOT RUN { # All the cars (nrow(mtcars)) # Only those in the top 2 groups based on the # carbs nrow(keep_top_n(mtcars, ~carb, n=2)) # }
Run the code above in your browser using DataLab