Learn R Programming

wakefield (version 0.3.6)

r_sample_ordered: Generate Random Ordered Factor Vector

Description

Generate a random vector and coerces to an ordered factor.

Usage

r_sample_ordered(n, x = LETTERS[1:5], prob = NULL, name = "Ordered")

Arguments

n

The number elements to generate. This can be globally set within the environment of r_data_frame or r_list.

x

A vector of elements to chose from.

prob

A vector of probabilities to chose from.

name

The name to assign to the output vector's varname attribute. This is used to auto assign names to the column/vector name when used inside of r_data_frame or r_list.

Value

Returns a random factor vector of elements.

See Also

sample, ordered

Examples

Run this code
# NOT RUN {
r_sample_ordered(100, name = "Var")

lvls <- c("Strongly Agree", "Agree", "Neutral", "Disagree", "Strongly Disagree")
table(r_sample_ordered(x = lvls, n=1000))

(out <- r_sample_ordered(x = c("Black", "Grey", "White"),
    prob = c(.5, .2, .3), n = 100))
slices <- c(table(out))
pie(slices, main="Pie Chart of Colors", col = tolower(names(slices)))
# }

Run the code above in your browser using DataLab