Reputation: 31
I'm looking for a way to sample numbers 1:40, 3812 times (length = 3812), with replacement - but restrict it such that each number doesn't get used more than 100 times.
Is there a way to build this type of restriction in the sampling command (sample()
)?
Upvotes: 3
Views: 45
Reputation: 70256
Here's an option:
sample(rep(1:40, 100), 3812)
Essentially, you start by building a vector of all possible numbers to sample from (rep(1:40, 100)
), i.e. each number occurs as often as the maximum number of times it should be sampled (100) and then sample from it without replacement.
Upvotes: 2