How can I partition a vector?
- by Karsten W.
How can I build a function
slice(x, n=2)
which would return a list of vectors where each vector except maybe the last has size n, i.e.
slice(letters, 10)
would return
list(c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j"),
c("k", "l", "m", "n", "o", "p", "q", "r", "s", "t"),
c("u", "v", "w", "x", "y", "z"))
?