library(groupedHyperframe.random)
# Loading required package: groupedHyperframe48 rfactor()
The examples in Chapter 48 require
Function groupedHyperframe.random::rfactor() is a wrapper of function base::sample.int(). Function rfactor()
- has first parameter
nof the random sample size, similar to functionsstats::rlnorm(),stats::rnbinom(), etc. - returns a
factor
Example: rfactor()
set.seed(18); rfactor(n = 20L, prob = c(4,2,3))
# [1] 2 3 2 1 1 3 1 3 1 1 3 3 1 1 2 1 3 1 2 1
# Levels: 1 2 3Example: rfactor() with levels
set.seed(18); rfactor(n = 20L, prob = c(4,2,3), levels = letters[1:3])
# [1] b c b a a c a c a a c c a a b a c a b a
# Levels: a b c