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 doesn't play well with desc #1008

Closed
HarlanH opened this issue Mar 9, 2015 · 2 comments
Closed

top_n doesn't play well with desc #1008

HarlanH opened this issue Mar 9, 2015 · 2 comments
Labels
Milestone

Comments

@HarlanH
Copy link

@HarlanH HarlanH commented Mar 9, 2015

It looks like top_n is a wrapper around filter(min_rank(desc())), which means that top_n(x, 1, desc(col)) causes a SQL syntax error, and of course there's no way to do top_n(x, 1, asc(col)).

Perhaps a bottom_n function that does the same thing, but without the hard-coded desc?

Workaround is trivial, of course, but the symmetric API would be handy!

Thanks!

@klmr
Copy link

@klmr klmr commented Mar 24, 2015

I think it also doesn’t work on data.frames but I might misunderstand the semantics. I’ve got a table with a column of p-values, and doing x %>% top_n(100, desc(pval)) returns a different set of of rows than x %>% arrange(pval) %>% head(100).

@hadley hadley added this to the 0.5 milestone May 19, 2015
@hadley hadley closed this in 9699289 Nov 4, 2015
@hadley
Copy link
Member

@hadley hadley commented Nov 4, 2015

I didn't check this with SQL, but I think using -n to indicate that you want the bottom n values is a reasonable compromise between concision and expression.

@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
3 participants