Skip to content

Instantly share code, notes, and snippets.

@johnbaums
Last active August 29, 2015 14:18
Show Gist options
  • Save johnbaums/dd7b6b5ae37bf73faae3 to your computer and use it in GitHub Desktop.
Save johnbaums/dd7b6b5ae37bf73faae3 to your computer and use it in GitHub Desktop.
Split vector x into groups with a specified number n of elements per group. If length(x) %% n is not 0, the final group will have fewer than n elements.
split_max_groupsize <- function(x, n) split(x, gl(ceiling(length(x)/n), n, length(x)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment