rfactor {regressinator}R 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))

[Package regressinator version 0.1.3 Index]