48  rfactor()

The examples in Chapter 48 require

library(groupedHyperframe.random)
# Loading required package: groupedHyperframe

Function groupedHyperframe.random::rfactor() is a wrapper of function base::sample.int(). Function rfactor()

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 3
Example: 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