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

Feature request: top_frac #4017

Closed
zx8754 opened this issue Dec 13, 2018 · 2 comments
Closed

Feature request: top_frac #4017

zx8754 opened this issue Dec 13, 2018 · 2 comments
Assignees
Labels
feature a feature request or enhancement
Milestone

Comments

@zx8754
Copy link

zx8754 commented Dec 13, 2018

Similar to sample_n and sample_frac, can we have top_frac?

Task: Using mtcars data, sort by mpg, then get 5%.

Currently, we could use top_n as below:

library(dplyr)
top_n(x = mtcars, n = round(nrow(mtcars) * 0.05), wt = mpg)
#    mpg cyl disp hp drat    wt  qsec vs am gear carb
# 1 32.4   4 78.7 66 4.08 2.200 19.47  1  1    4    1
# 2 33.9   4 71.1 65 4.22 1.835 19.90  1  1    4    1

But with top_frac it would look neater, something like:

top_frac(x = mtcars, size = 0.05, wt = mpg)
@romainfrancois romainfrancois added the feature a feature request or enhancement label Dec 13, 2018
@romainfrancois
Copy link
Member

Before we can do that, top_n() should allow quosures for n, i.e. this should be alright:

library(dplyr, warn.conflicts = FALSE)

top_n(mtcars, n() / 2)
#> Selecting by carb
#> n() should only be called in a data context

Created on 2019-06-10 by the reprex package (v0.2.1)

@romainfrancois romainfrancois added this to the 0.8.2 milestone Jun 10, 2019
@romainfrancois romainfrancois self-assigned this Jun 10, 2019
@lock
Copy link

lock bot commented Dec 8, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Dec 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants