How to generate random number 1 & 2 instead of 0 & 1 from binomial distribution?

719 Views Asked by At

I would like to generate random number from binomial 1 or 2 instead of the usual 0 and 1. Normally we will use rbinom(10, 1, 0.4) to generate either 0 or 1, but is it possible to generate 1 and 2? Or is there any way to convert it?

1

There are 1 best solutions below

0
StupidWolf On BEST ANSWER

You can do:

rbinom(10, 1, 0.4) + 1

Or use sample:

sample(1:2, 10, prob=c(0.6,0.4), replace=TRUE)