vec_sample: Re-implementation of 'base::sample()' Using the vctrs Package

View source: R/randomize.R

vec_sampleR Documentation

Re-implementation of base::sample() Using the vctrs Package

Description

sample() behaves unexpectedly when called on objects other than atomic vectors. This re-implementation has identical logic but uses the vctrs package to generalize to other inputs. Parameters are modeled after slice_sample().

Usage

vec_sample(.x, n, replace = FALSE, weight_by = NULL)

Arguments

.x

The data to sample

n

The number of samples to return

replace

Should sampling be performed with (TRUE) or without (FALSE, the default) replacement?

weight_by

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.


jesse-smith/coviData documentation built on Jan. 14, 2023, 11:08 a.m.