Likert quantile function

qlikert(p, prob, labels = names(prob))

Arguments

p

the vector of probabilities

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 of the quantiles

Examples

p <- seq(0, 1, .1)
prob <- c(.1, .2, .4, .2, .1)
qlikert(p, prob)
#>  [1] 1 1 2 2 3 3 3 3 4 4 5

p <- seq(0, 1, .1)
prob <- c(A = 10, B = 20, C = 30)
qlikert(p, prob)
#>  [1] A A B B B B C C C C C
#> Levels: A B C

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