Created
November 25, 2015 03:10
-
-
Save wdkrnls/83b0118ecb660eacd20c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Clever chunking algorithm into roughly equal parts | |
#' http://stackoverflow.com/questions/2130016/splitting-a-list-of-arbitrary-size-into-only-roughly-n-equal-parts | |
chunk <- function(x, k) { | |
n <- length(x) | |
q <- n %/% k | |
r <- n %% k | |
lapply(seq.int(1, k), function(i) { | |
x[seq(from = (i - 1)*q + min(i - 1, r) + 1, to = i * q + min(i, r))] | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment