Skip to contents

Split to chunks of size n

Usage

chunks_of_n(d, n, label = NULL, even = FALSE, pattern = NULL)

Arguments

d

data. Can be vector or data frame.

n

number of chunks

label

naming prefix for chunk names

even

boolean to set if size of chunks should be evenly distributed.

pattern

regex pattern to extract names from provided vector. If data frame, will assume first column is name.

Value

List of length n

Examples

tail(chunks_of_n(seq_len(100), 7), 3)
#> $`13`
#> [1] 85 86 87 88 89 90 91
#> 
#> $`14`
#> [1] 92 93 94 95 96 97 98
#> 
#> $`15`
#> [1]  99 100
#> 
tail(chunks_of_n(seq_len(100), 7, even = TRUE), 3)
#> $`13`
#> [1] 83 84 85 86 87 88
#> 
#> $`14`
#> [1] 89 90 91 92 93 94
#> 
#> $`15`
#> [1]  95  96  97  98  99 100
#>