powered by
This function either
splits a vector into n chunks of equal size (type = 1),
n
type = 1
splits a vector into chunks of size n (type = 2).
type = 2
chunk_vector(x, n, type = 1, strict = FALSE)
A list.
list
[atomic()`] A vector of elements.
[integer(1)] A number smaller or equal length(x).
integer(1)
length(x)
[1 | 2] Either
1
2
1 (default) to split x into n chunks of equal size,
x
or 2 to split x into chunks of size n.
[logical(1)] Set to TRUE to fail if length(x) is not a multiple of n, or FALSE (default), else.
logical(1)
TRUE
FALSE
Other vector helpers: check_numeric_vector(), check_probability_vector(), insert_vector_entry(), map_indices(), match_numerics(), permutations(), split_vector_at(), subsets(), vector_occurrence()
check_numeric_vector()
check_probability_vector()
insert_vector_entry()
map_indices()
match_numerics()
permutations()
split_vector_at()
subsets()
vector_occurrence()
x <- 1:12 chunk_vector(x, n = 3, type = 1) chunk_vector(x, n = 3, type = 2) try(chunk_vector(x, n = 5, strict = TRUE))
Run the code above in your browser using DataLab