Random Likert distribution

rlikert(n, prob, labels = names(prob))

Arguments

n

the number of observations

prob

a vector of probabilities or counts; if named, the output is a factor

labels

a vector of values, defaults to names(prob) or 1:length(prob), if numeric, the output is numeric

Value

a vector sampled from a likert distribution with the specified parameters

Examples

# no names or labels returns integer vector of values 1:length(prob)
prob <- c(.1, .2, .4, .2, .1)
rlikert(10, prob)
#>  [1] 4 1 4 4 3 4 2 4 4 2

# named prob returns factor 
prob <- c(A = 10, B = 20, C = 30)
rlikert(10, prob)
#>  [1] A B B C C C B A C C
#> Levels: A B C

# specify labels if prob not named and not 1:length(prob)
labels <- -2:2 
prob <- rep(1, length(labels)) # uniform probability
rlikert(10, prob, labels)
#>  [1]  0  0 -1  0  0  0 -1  1 -1  0