Created
November 16, 2016 13:24
-
-
Save btupper/20879e0b46e5ed63d402d7cff424dbb7 to your computer and use it in GitHub Desktop.
Split a vector into a list of smaller vectors
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
#' Split a vector into groups of MAX (or possibly fewer) | |
#' | |
#' @param v vector or list to split | |
#' @param MAX numeric the maximum size per group | |
#' @return a list of the vector split into groups | |
split_vector <- function(v, MAX = 200){ | |
nv <- length(v) | |
if (nv <= MAX) return(list('1' = v)) | |
split(v, findInterval(1:nv, seq(from = 1, to = nv, by = MAX))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment