select_sample: Randomly select samples from a sampling frame with or without...

Description Usage Arguments Value Examples

Description

Given a data.frame with sample size allocation per strata and a data.frame with the sampling frame it selects random samples.

Usage

1
2
select_sample(allocation, sampling_frame, sample_size = sample_size,
  stratum = stratum)

Arguments

allocation

data.frame with a column defining the strata and a column with sample size allocations for each stratum (one line per stratum).

sampling_frame

data.frame with the sampling frame it must contain a column with the stratum.

sample_size

unquoted column with sample sizes in the allocation data.frame

stratum

unquoted column with strata in the allocation and sampling_frame data.frame's (the columns must have the same name in the two data.frame's)

Value

A data.frame with the selected sample, it will have the same columns as the original sampling frame plus a column indicating the sample size in the stratum of each selected observation.

Examples

1
2
3
4
5
6
7
sampling_frame <- data.frame(id = 1:100,
  str = sample(1:5, 100, replace = TRUE),
  val = rnorm(100))
allo <- sampling_frame %>%
    group_by(str) %>%
    summarise(n = 0.4 * n())
select_sample(allo, sampling_frame, n, str)

tereom/mapacurracy documentation built on May 26, 2019, 5:31 a.m.