Skip to content

Instantly share code, notes, and snippets.

@jakosz
Created February 11, 2014 12:45
Show Gist options
  • Save jakosz/8934204 to your computer and use it in GitHub Desktop.
Save jakosz/8934204 to your computer and use it in GitHub Desktop.
# Groups indices of a list or vector into n (almost) equal chunks:
iTable <-
function (x, n)
{
x = seq_along(x)
i = floor(seq(from = x[1], to = x[length(x)], length.out = n +
1))
res = data.frame(from = i[1:(length(i) - 1)], to = i[2:length(i)])
res$from[2:nrow(res)] = res$from[2:nrow(res)] + 1
return(res)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment