split_size: Split a vector into chunks of size 'n'

View source: R/vector_tools.R

split_sizeR Documentation

Split a vector into chunks of size n

Description

In contrast to desiderata::assign_groups() which splits a vector into n chunks (possibly with a different number of entries per chunk), desiderata::split_size() splits a vector into an arbitrary number of chunks as long as each chunk has n or fewer entries inside it.

Usage

split_size(vec, size)

Arguments

vec

(Vector) Any vector.

size

(Integer) The number of entries per chunk.

Value

A list of dynamic length, where each entry is a chunk from vec of length 1 up to size.

Authors

Source

https://stackoverflow.com/a/3321659/5578429

Examples

split_size(letters, 5)

## $`1`
## [1] "a" "b" "c" "d" "e"
## 
## $`2`
## [1] "f" "g" "h" "i" "j"
## 
## $`3`
## [1] "k" "l" "m" "n" "o"
## 
## $`4`
## [1] "p" "q" "r" "s" "t"
## 
## $`5`
## [1] "u" "v" "w" "x" "y"
## 
## $`6`
## [1] "z"


DesiQuintans/desiderata documentation built on April 9, 2023, 5:43 a.m.