rfactor | R Documentation |
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.
rfactor(n, levels, prob = rep_len(1/length(levels), length(levels)))
n |
Number of values to draw |
levels |
Character vector specifying the levels for the factor |
prob |
Vector specifying the probability for each factor level |
Sample of n
values from levels
, drawn in proportion to their
probabilities. By default, levels are equally likely.
by_level()
to assign numeric values based on factor levels, such
as to set population regression coefficients by factor level
rfactor(5, c("foo", "bar", "baz"), c(0.4, 0.3, 0.3))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.