Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

top_n(10, -n) vs. btm_n(10, n) #1352

Closed
npjc opened this issue Aug 26, 2015 · 5 comments
Closed

top_n(10, -n) vs. btm_n(10, n) #1352

npjc opened this issue Aug 26, 2015 · 5 comments
Labels
Milestone

Comments

@npjc
Copy link
Contributor

@npjc npjc commented Aug 26, 2015

I use count(group) %>% top_n(10, -n) type-of-thing lots... Future me would prefer if I could use count(group) %>% btm_n(10, n) instead as it is more easily understood at a glance.

From ?top_n():

# Find 10 players with most games
require("Lahman")
tbl_df(Batting) %>%
  group_by(playerID) %>%
  tally(G) %>%
  top_n(10)

I wish for:

# to find the 10 players with least games
# currently
... %>% top_n(10, -n)
# wishful behaviour
... %>% btm_n(10, n)

Or perhaps it is easier to just document examples of how you'd get the bottom n of something under top_n()

@ghost
Copy link

@ghost ghost commented Sep 1, 2015

Agreed. I was just searching for how to do this and believe the alternative suggested (btm_n) would be preferred

@hadley hadley added the feature label Oct 21, 2015
@hadley hadley added this to the 0.5 milestone Oct 21, 2015
@hadley
Copy link
Member

@hadley hadley commented Nov 4, 2015

But top_n() with a negative value doesn't work?

@hadley
Copy link
Member

@hadley hadley commented Nov 4, 2015

Ooooh, you're negating the variable n, not the argument n.

@hadley hadley closed this in 9699289 Nov 4, 2015
@hadley
Copy link
Member

@hadley hadley commented Nov 4, 2015

I think using -n to indicate that you want the bottom n values is a reasonable compromise between concision and expression.

@npjc
Copy link
Contributor Author

@npjc npjc commented Nov 4, 2015

I'm surprised. A quick survey of students learning R 2/15 were able to "read off" what was going to happen. But thanks for considering.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants