apache / apache/arrow

[R] Implement dplyr::slice_sample()

Open
#20,417 0 comments 0 reactions 0 assignees View on GitHub
Component: R Type: task
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.