powered by
Select the top or bottom entries in each group, ordered by wt.
wt
top_n.(.df, n = 5, wt = NULL, .by = NULL)
A data.frame or data.table
Number of rows to return
Optional. The variable to use for ordering. If NULL uses the last column in the data.table.
Columns to group by
# NOT RUN { test_df <- data.table( x = 1:5, y = 6:10, z = c(rep("a", 3), rep("b", 2))) test_df %>% top_n.(2, wt = y) test_df %>% top_n.(2, wt = y, .by = z) # }
Run the code above in your browser using DataLab