vendredi 28 septembre 2018

Random allocation in R with runif()

In R, I would like to be able to randomly assign values to groups.

If G = number of groups and V = number of values, with G <= V, I want allocation in the range of [1, V / G] inclusive. The caveat is that the total number of values across all groups must be fixed at V.

Ex. If G = 3 and V = 21, I can have (7, 7, 7) or (10, 6, 5) or ...

Is there a straightforward way of doing this with runif() (which doesn't include endpoints)? The caveat mentioned above is the complicated part.

Any thoughts?




Aucun commentaire:

Enregistrer un commentaire