Splits a vector into list of vectors by chunk or size

split_vector(vec, chunks = NA, percent = NA, size = NA)

Arguments

vec

vector; The vector to split

chunks

integer; x > 0; The number of desired sub-lists

percent

numeric; 100 > x > 0; The maximum percentage of elements each sub-list should hold

size

integer; x > 0; The maximum size of each sub-list

Value

A list of sub-vectors

Details

Splits a vector into consistantly sized sub-lists. The sub-list size will always be decreasing based on list order.

Examples

# Split vector into 4 sub vectors split_vector(c(1,2,3,4,5,6,7,8),chunks=4)
#> [[1]] #> [1] 1 2 #> #> [[2]] #> [1] 3 4 #> #> [[3]] #> [1] 5 6 #> #> [[4]] #> [1] 7 8 #>
# Split vector into sub-vectors with a size of 2 split_vector(c(1,2,3,4,5,6,7,8),size=2)
#> [[1]] #> [1] 1 2 #> #> [[2]] #> [1] 3 4 #> #> [[3]] #> [1] 5 6 #> #> [[4]] #> [1] 7 8 #>
# Split vector into sub-vectors each with 25% of the total elements split_vector(c(1,2,3,4,5,6,7,8),percent=25)
#> [[1]] #> [1] 1 2 #> #> [[2]] #> [1] 3 4 #> #> [[3]] #> [1] 5 6 #> #> [[4]] #> [1] 7 8 #>