syssamp: Systematic sample from a dataset

Description Usage Arguments Value References Examples

View source: R/syssamp.R

Description

Takes a dataset, sorts it by one or more variables, and draws samples at regular intervals. A fractional skip interval is used so that each record still has an equal probability of selection when the number of records in the frame is not evenly divisible by the sample size.

Usage

1
syssamp(.data, size, stratvars, return_indices = TRUE, seed = NA)

Arguments

.data

A dataset, in data.frame or tibble format.

size

The size of the desired sample.

stratvars

Names of variables by which the sampling frame will be sorted

return_indices

Return a vector containing the indices of the selected records. Defaults to TRUE. If FALSE, a data.frame containing the sampled records will be returned.

seed

Optional. Ensures that the same sample will be created if the code is rerun.

Value

Either a vector of indices or a data.frame/tibble.

References

Buskirk, T.D. (2008) Sampling interval. In P.J. Lavrakas, Encyclopedia of survey research methods. Thousand Oaks, CA: Sage Publications.

Examples

1
2
3
dec13_sample_indices <- syssamp(dec13_excerpt, size = 10, stratvars = c("sex", "recage"))
dec13_sample <- syssamp(dec13_excerpt, size = 10, stratvars = c("sex", "recage"),
                        return_indices = FALSE)

pewresearch/pewmethods documentation built on March 27, 2020, 7:22 p.m.