[R] Implement dplyr::slice_sample()
- Dominant language
- C++
- Stars
- 17.1k
- Forks
- 4.3k
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 91
Description
```Java
slice_sample(.data, ..., n, prop, weight_by = NULL, replace = FALSE)
```
If `n` is provided, compute `nrow(.data)`, and if that is not NA, convert to a {prop}. (Might want to do prop + .01 or something and then do head(n) after, i.e. sample more than you need and then take `n`, just so you don't by randomness get fewer than n.)
With prop, turn this into `filter(arrow_random() < prop)`. See ARROW-17572.
Defer weight_by to a followup. It should be doable but might be expensive (need to scan everything to compute sum and ensure that all values are positive).
Defer replace = TRUE.
Also probably can only do if .data is ungrouped, I think the dplyr methods do sampling within groups.
**Reporter**: [Neal Richardson](https://issues.apache.org/jira/browse/ARROW-17759) / @nealrichardson
**Note**: *This issue was originally created as [ARROW-17759](https://issues.apache.org/jira/browse/ARROW-17759). Please see the [migration documentation](https://github.com/apache/arrow/issues/14542) for further details.*
Contributor guide
Research direction
Start by reading the existing dplyr methods and the behavior described in ARROW-17572. Implement ungrouped slice_sample() support for n and prop, using arrow_random() for prop; leave weight_by and replace = TRUE deferred. Done means the supported sampling modes work without promising grouped behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100