Skip to content
Prev 227313 / 398500 Next

Generate groups with random size but given total sample size

Dear list,
I am currently doing some simulation studies where I want to compare different scenarios.
In particular, two scenarios should be compared: 10.000 cases in 100 groups with 100 cases per group and 10.000 cases in 100 groups with random group size (ranging from 5 to 500).

The first part is no problem:
But I don't get along with the second scenario. Using sample does give me 100 groups with random cases, but generates more than 10.000 cases:
[1] 24583

Another way could be generating one sample at a time and sum the cases. But this would end up in trail & error to fit the 10.000 cases. Maybe it would break rules of probability, too.

I'm convinced that there should be another (and even better) way to handle this problem in R... :-)


Best regards,
Arne Schulz