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.
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)
} # }