10

I'm trying to generate a set of 100 random integers between a fixed range. One could be comprised of 100 numbers between 1 and 3, with specific probabilities of obtaining either 1, 2 and 3.

Any help would be appreciated!

1 Answer 1

24

See ?sample.

For example:

sample(c(1, 2, 3), size = 100, replace = TRUE, prob = c(0.1, 0.5, 0.4)) 
Sign up to request clarification or add additional context in comments.

1 Comment

how about if the range between 1 to 20 and the probabilities of obtaining likes 18.7, 11,6. cannot list all the number, how to do it?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.