Skip to content
Prev 389076 / 398506 Next

Splitting a data column randomly into 3 groups

In case anyone is still interested in my query, note that if there are
n total items to be split into g groups as evenly as possible, if we
define this as at most two different size groups whose size differs by
1, then:

if n = k*g + r, where 0 <= r < g,
then n = k*(g - r) + (k + 1)*r  .
i.e. g-r groups of size k and r groups of size k+1

So using R's modular arithmetic operators, which are handy to know
about, we have:

r = n %% g and k = n %/% g .

(and note that you should disregard my previous stupid remark about
numerical analysis).

Cheers,
Bert
On Sat, Sep 4, 2021 at 3:34 PM Bert Gunter <bgunter.4567 at gmail.com> wrote: