Description Usage Arguments Details Examples
keep_top_n
takes a data frame and filters it to only return the rows
coinciding with the top n of a given column. This enables the user to quickly
extract data based on the first or largest of something.
1 | keep_top_n(.data, .ranking_col, n = 1)
|
.data |
A |
.ranking_col |
The column used to filter the data |
n |
The number of rows to keep |
The ranking mechanism uses the dplyr::row_number
. This means if there
are any ties when ranking the data, the data corresponding to the first
row positionally is kept.
1 2 3 4 5 6 7 8 9 10 11 | library(dplyr)
data("starwars")
starwars %>%
group_by(gender) %>%
keep_top_n(height)
starwars %>%
group_by(gender) %>%
keep_top_n(desc(height), n = 3)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.