Create a small stratified sample from the given data
Source:R/test-helpers.R
get_stratified_samp.Rd
Create a small stratified sample from the given data
Arguments
- .data
A data frame or data frame extension (e.g. a tibble).
- strata
A character vector of variables (column names) on which to stratify.
- n_per_stratum
Sample size per stratum. Default: 3
- replace
A boolean: whether to sample with replacement or not. Default: FALSE
- seed_val
An integer for setting the RNG seed. Default: 123
Examples
df <- data.frame(
group = rep(c("A", "B", "C"), each = 4),
subgroup = rep(c("X", "Y"), times = 6),
value = 1:24
)
df %>% get_stratified_samp(c("group", "subgroup"), n_per_stratum = 2)
#> # A tibble: 12 × 3
#> group subgroup value
#> <chr> <chr> <int>
#> 1 A X 1
#> 2 A X 13
#> 3 A Y 16
#> 4 A Y 14
#> 5 B X 5
#> 6 B X 7
#> 7 B Y 18
#> 8 B Y 20
#> 9 C X 21
#> 10 C X 11
#> 11 C Y 10
#> 12 C Y 24
if (FALSE) { # \dontrun{
get_tus_dat() %>% get_stratified_samp()
} # }