Generates category assignments with specified proportions.
Handles NA proportions (uniform fallback) and validates inputs.
Usage
sample_with_proportions(categories, proportions, n, seed = NULL)
Arguments
- categories
Character or numeric vector. Category values.
- proportions
Numeric vector. Proportions (same length, sum to 1.0).
- n
Integer. Number of samples.
- seed
Integer. Optional random seed.
Value
Vector of length n with category assignments.
See also
Other mockdata-helpers:
apply_garbage(),
apply_missing_codes(),
apply_rtype_defaults(),
extract_distribution_params(),
extract_proportions(),
generate_garbage_values(),
get_cycle_variables(),
get_raw_variables(),
get_variable_details(),
has_garbage(),
make_garbage()
Examples
if (FALSE) { # \dontrun{
categories <- c("1", "2", "7", "9")
proportions <- c(0.4, 0.52, 0.03, 0.05)
assignments <- sample_with_proportions(categories, proportions, n = 1000)
} # }