
Sampling from the multinomial equivalent of the Bernoulli distribution
Source:R/import-standalone-distributions.R
rcategorical.RdSampling from the multinomial equivalent of the Bernoulli distribution
Value
a vector of random class labels of length n. Labels come from names
of prob or from a character vector in factor.
Examples
prob = c("one"=0.1,"two"=0.2,"seven"=0.7)
table(rcategorical(1000,prob))
#>
#> one seven two
#> 83 700 217
rcategorical(10,prob,factor=TRUE)
#> [1] one one one seven seven one seven seven seven two
#> Levels: one two seven
rcategorical(10,rep(1,26),factor=letters)
#> [1] o u f r f l w j i w
#> Levels: a b c d e f g h i j k l m n o p q r s t u v w x y z