moodymudskipper / tb

IN ~PROGRESS my own take on `[.data.frame`
0 stars 0 forks source link

top_n feature #38

Open moodymudskipper opened 4 years ago

moodymudskipper commented 4 years ago

top_n is a row selection feature, so it could be a special function to be used in i. It would work with the "along" notation too. dplyr puts "n" argument first, and variable is optional, I think I prefer to have the variable first and n defaulting to 1.

iris %tb>% .[top(Sepal.Width) ~ Species,]

# equivalent to
iris %>%
  group_by(Species) %>%
  top_n(1, Sepal.Width) %>%
  ungroup()
moodymudskipper commented 4 years ago

for the same price let's have bottom

We can have a 2nd argument named n and a third argument named pct, they can't be given at the same time.

Would be nice to have another argument for corner cases, what if we have 2 maxima ? we can take inspiration of different ordering algos.