I have a data frame with probabilities for three outcomes: A, B and C. Their probabilities are prob1, prob2, and prob3:
df = data.frame(prob1=runif(1000,0,0.2),prob2=runif(1000,0,0.1))
df$prob3 = 1-df$prob1-df$prob2
I am trying to simulate an outcome for each row given its unique probabilities and run the following loop:
df$outcome = NA
for (i in 1:1000) {
df$outcome[i]<-sample(c(A,B,C), 1, prob = c(df$prob1[i],df$prob2[i],df$prob3[i]), replace = FALSE)
}
I have a large data set and would like to avoid loops. How can I do that?