Skip to contents

Takes a sample with or without replacement from the population.

Usage

rsample(N, n, strata = NULL, balance = FALSE, replace = FALSE)

Arguments

N

population size.

n

sample size.

strata

(optional) vector of stratification variables. If provided must be of length N

balance

logical, whether to (try to) balance the strata frequency in the output sample. Used only if strata is provided.

replace

logical, whether to sample with replacement. Default is FALSE. Set to TRUE for bootstrap method.

Value

A vector of length n containing the index of the computed random set of observations.

Details

If strata is provided, sampling is applied within each stratum, with the strategy depending on balance. If balance = FALSE, the proportion of the strata in the population is maintained in the samples (also called "proportionate allocation"). If balance = TRUE, the proportion of strata in the sample is attempted to be balanced.

Author

Alessandro Barberis