Created
January 31, 2017 02:10
-
-
Save wdkrnls/9e49a18ccf58f3bcd30dd9b7cba0e684 to your computer and use it in GitHub Desktop.
Chunk a text string into k strings.
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
chunk_text <- function(txt, k) { | |
n <- nchar(txt) | |
q <- n %/% k | |
r <- n %% k | |
unlist(lapply(seq.int(1, k), function(i) { | |
substr(txt, start = (i - 1)*q + min(i - 1, r) + 1, stop = i * q + min(i, r)) | |
}), recursive = FALSE) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment