Sample function for logs
Usage
slice_sample(.data, ..., n, prop, by = NULL, weight_by = NULL, replace = FALSE)
# S3 method for class 'log'
slice_sample(.data, ..., n, prop, weight_by = NULL, replace = FALSE)
# S3 method for class 'grouped_log'
slice_sample(.data, ..., n, prop, weight_by = NULL, replace = FALSE)
Arguments
- .data
A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr). See Methods, below, for more details.
- ...
Arguments passed on to
dplyr::slice_sample
n,prop
Provide either
n
, the number of rows, orprop
, the proportion of rows to select. If neither are supplied,n = 1
will be used. Ifn
is greater than the number of rows in the group (orprop > 1
), the result will be silently truncated to the group size.prop
will be rounded towards zero to generate an integer number of rows.A negative value of
n
orprop
will be subtracted from the group size. For example,n = -2
with a group of 5 rows will select 5 - 2 = 3 rows;prop = -0.25
with 8 rows will select 8 * (1 - 0.25) = 6 rows.
- n, prop
Provide either
n
, the number of rows, orprop
, the proportion of rows to select. If neither are supplied,n = 1
will be used. Ifn
is greater than the number of rows in the group (orprop > 1
), the result will be silently truncated to the group size.prop
will be rounded towards zero to generate an integer number of rows.A negative value of
n
orprop
will be subtracted from the group size. For example,n = -2
with a group of 5 rows will select 5 - 2 = 3 rows;prop = -0.25
with 8 rows will select 8 * (1 - 0.25) = 6 rows.- by
-
<
tidy-select
> Optionally, a selection of columns to group by for just this operation, functioning as an alternative togroup_by()
. For details and examples, see ?dplyr_by. - weight_by
<
data-masking
> Sampling weights. This must evaluate to a vector of non-negative numbers the same length as the input. Weights are automatically standardised to sum to 1.- replace
Should sampling be performed with (
TRUE
) or without (FALSE
, the default) replacement.
Methods (by class)
slice_sample(log)
: Samplen
cases of alog
.slice_sample(grouped_log)
: Samplen
cases from agrouped_log
.