Learn R Programming

decisionSupport (version 1.114)

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)

Value

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

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.

Author

Eike Luedeling

Examples

Run this code

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