|
19 | 19 | #' intrinsic notion of row order. If you want to perform the equivalent
|
20 | 20 | #' operation, use [filter()] and [row_number()].
|
21 | 21 | #'
|
| 22 | +#' For `slice_sample()`, note that the weights provided in `weight_by` are |
| 23 | +#' passed through to the `prob` argument of [base::sample.int()]. This means |
| 24 | +#' they cannot be used to reconstruct summary statistics from the underlying |
| 25 | +#' population. See [this discussion](https://stats.stackexchange.com/q/639211/) |
| 26 | +#' for more details. |
| 27 | +#' |
22 | 28 | #' @family single table verbs
|
23 | 29 | #' @inheritParams args_by
|
24 | 30 | #' @inheritParams arrange
|
|
93 | 99 | #' mtcars %>% slice_sample(n = 5)
|
94 | 100 | #' mtcars %>% slice_sample(n = 5, replace = TRUE)
|
95 | 101 | #'
|
96 |
| -#' # you can optionally weight by a variable - this code weights by the |
| 102 | +#' # You can optionally weight by a variable - this code weights by the |
97 | 103 | #' # physical weight of the cars, so heavy cars are more likely to get
|
98 |
| -#' # selected |
| 104 | +#' # selected. |
99 | 105 | #' mtcars %>% slice_sample(weight_by = wt, n = 5)
|
100 | 106 | #'
|
101 | 107 | #' # Group wise operation ----------------------------------------
|
@@ -293,6 +299,8 @@ slice_max.data.frame <- function(.data, order_by, ..., n, prop, by = NULL, with_
|
293 | 299 | #' @param weight_by <[`data-masking`][rlang::args_data_masking]> Sampling
|
294 | 300 | #' weights. This must evaluate to a vector of non-negative numbers the same
|
295 | 301 | #' length as the input. Weights are automatically standardised to sum to 1.
|
| 302 | +#' See the `Details` section for more technical details regarding these |
| 303 | +#' weights. |
296 | 304 | slice_sample <- function(.data, ..., n, prop, by = NULL, weight_by = NULL, replace = FALSE) {
|
297 | 305 | check_dot_by_typo(...)
|
298 | 306 | check_slice_unnamed_n_prop(..., n = n, prop = prop)
|
|
0 commit comments