Search code examples
rstatisticsdistribution

Create a vector with known outcomes and probabilities


I would like to create a variable in R where I have known probabilities and outcomes. For example, a vector of length 5000 with 2 possible outcomes 1 and 1.5 where 1 turns up 65% of the time and 1.5 turns up 35% of the time.

Expanding on this, if I could create a vector that has more than 2 outcomes with more than 2 probabilities. For example, the numbers 1,2,3 come up 25% 25% and 50% of the time.

edit* Going off of Akrun advice, I am doing:

x = c(rep(1,65), rep(1.5, 35))
sample(x,10)

Is this the appropriate method?


Solution

  • We can use sample

    sample(1:3, 5000, replace = TRUE, prob = c(.25, .25, .50))