top_n in dplyr is doing almost what I want; however, when there are ties it returns all, but I would like it to randomly select among the ties to satisfy my cutoff of 2 rows.
top_number=2
x <- c(1, 3, 4, 6, 6, 6)
y <- c(3, 2, 5, 1, 3, 3)
xy <- data.frame(x, y)
xy
xy_1 <- dplyr::top_n(xy, top_number, wt = x)
xy_1
As you can see I get 3 rows, not 2. Would be nice with a tidyverse solution.