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

Provide methods for new slice helpers #394

Closed
hadley opened this issue Jan 3, 2020 · 2 comments
Closed

Provide methods for new slice helpers #394

hadley opened this issue Jan 3, 2020 · 2 comments
Labels
feature a feature request or enhancement
Milestone

Comments

@hadley
Copy link
Member

hadley commented Jan 3, 2020

And provide an informative error for the slice() method.

@hadley hadley added this to the 2.0.0 milestone Jan 3, 2020
@hadley hadley added the feature a feature request or enhancement label Apr 14, 2020
@hadley
Copy link
Member Author

hadley commented Sep 17, 2020

Look at #64 for implementation ideas.

@hadley
Copy link
Member Author

hadley commented Sep 25, 2020

  • slice_head(), slice_tail()
  • slice_min(), slice_max(),
  • slice_sample()

All also work on groups, so I think will be translated into filter() calls.

# slice_min(x, n = 2)
lazy_frame(x = 1, g = 2) %>% 
  group_by(g) %>% 
  window_order(x) %>% 
  filter(min_rank() <= 2)

# slice_min(x, prop = 0.2)
lazy_frame(x = 1, g = 2) %>% 
  group_by(g) %>% 
  window_order(x) %>% 
  filter(cume_dist() <= 0.2)

# slice_min(x, n = 2, with_ties = FALSE)
lazy_frame(x = 1, g = 2) %>% 
  group_by(g) %>% 
  window_order(x) %>% 
  filter(row_number() <= 2)

# slice_min(x, prop = 0.2, with_ties = FALSE)
# error

# slice_max(x, n = 2)
lazy_frame(x = 1, g = 2) %>% 
  group_by(g) %>% 
  window_order(desc(x)) %>% 
  filter(min_rank() <= 2)

# slice_random(x, n = 2)
lazy_frame(x = 1, g = 2) %>% 
  group_by(g) %>% 
  window_order(RANDOM()) %>% 
  filter(min_rank() <= 2)

@hadley hadley closed this as completed in c4072d7 Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant