r_sample_ordered: Generate Random Ordered Factor Vector

Description Usage Arguments Value See Also Examples

View source: R/r_sample_ordered.R

Description

Generate a random vector and coerces to an ordered factor.

Usage

1
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

1
2
3
4
5
6
7
8
9
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)))

wakefield documentation built on Sept. 14, 2020, 1:07 a.m.