Learn R Programming

decisionSupport (version 1.103.8)

random_state: Draw a random state for a categorical variable

Description

This function draws a sample from a user-defined frequency distribution for a categorical variable.

Usage

random_state(states, probs)

Arguments

states

character vector containing state names.

probs

numeric vector containing probabilities for the states. If these do not add up to 1, they are automatically normalized.

Value

one of the states, drawn randomly according to the specified probabilities.

Examples

Run this code
# NOT RUN {
random_state(states=c("very low","low","medium","high","very high"),
  probs=c(1,1,2,1,1))

# }

Run the code above in your browser using DataLab