Keeps a random sample of rows of a GPU table, as dplyr::slice_sample()
does. The row numbers are drawn in R with the same sample.int() calls
dplyr makes, so the same set.seed() gives the same rows as dplyr; the
rows are then gathered on the GPU. This works ungrouped, after
group_by() and with by. A lazy table's pending steps run first, since
the draw needs the row count. weight_by runs in dplyr on the CPU (see
cuplyr-fallback), since the weights are values of the data.
Usage
# S3 method for class 'tbl_gpu'
slice_sample(.data, ..., n, prop, by = NULL, weight_by = NULL, replace = FALSE)Arguments
- .data
A
tbl_gpuobject created bytbl_gpu().- ...
Not used; for extensibility, must be empty.
- n
Number of rows to sample. Default
1if neithernnorpropis supplied. Negative values are clamped likeslice_head.tbl_gpu()'sn. Withreplace = TRUE, a non-negativen/propis not clamped to the table's (or group's) row count: oversampling with replacement is allowed and gives a larger result; withoutreplace, oversampling silently clamps (no error).- prop
Proportion of rows to sample (
n = prop * nrow(.data), subject to the same clamp rule asn).- by
Optional grouping columns for this call only, run on the GPU. As in dplyr, the groups are drawn (and appear in the result) in the order each one first appears in
.data, and the result is ungrouped. Supplyingbywhen.datais already grouped (viagroup_by()) is an error, as in dplyr.- weight_by
Sampling weights. A call with
weight_byruns in dplyr on the CPU.- replace
Whether to sample with replacement.
