chunks_of_n {stRoke}R Documentation

Split to chunks of size n

Description

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)
tail(chunks_of_n(seq_len(100),7,even=TRUE),3)
ds <- data.frame(nm=paste0("Sub",
add_padding(rownames(stRoke::talos))),stRoke::talos)
head(chunks_of_n(ds,7,pattern="Sub[0-9]{3}",label="grp"),2)
## Please notice that no sorting is performed. This is on purpose to preserve
## original sorting. If sorting is intended, try something like this:
ds[order(ds$nm),] |> chunks_of_n(7,pattern="Sub[0-9]{3}",label="grp") |> 
head(2)

[Package stRoke version 23.9.1 Index]