rfactor: Draw random values from a factor variable

View source: R/factors.R

rfactorR Documentation

Draw random values from a factor variable

Description

To specify the population distribution of a factor variable, specify the probability for each of its factor levels. When drawn from the population, factor levels are drawn with replacement according to their probability.

Usage

rfactor(n, levels, prob = rep_len(1/length(levels), length(levels)))

Arguments

n

Number of values to draw

levels

Character vector specifying the levels for the factor

prob

Vector specifying the probability for each factor level

Value

Sample of n values from levels, drawn in proportion to their probabilities. By default, levels are equally likely.

See Also

by_level() to assign numeric values based on factor levels, such as to set population regression coefficients by factor level

Examples

rfactor(5, c("foo", "bar", "baz"), c(0.4, 0.3, 0.3))

regressinator documentation built on Sept. 11, 2024, 6:50 p.m.