Making random, equally-sized partitions

Sometimes, as with cross-validation, one needs to generate k partitions, each with an equal number of observations.

There are probably an infinite number of ways this could be done in R, but the Gist below illustrates one way to do it in four lines, while ensuring that the partition counts are as equal as possible.

By d-sparks

Tags: crossValidation random rstats