Skip to contents

Divides a ts object into equal-length segments (batches) of duration t_bch seconds. If a dqmask attribute is present and has.DQ = TRUE, it is also split and attached to each batch.

Usage

batching(ts, t_bch = 1, has.DQ = T)

Arguments

ts

A ts object with optional dqmask attribute.

t_bch

A numeric. Desired batch length in seconds (default: 1).

has.DQ

Logical (default: TRUE). Whether to also batch the dqmask attribute if present.

Value

A named list of ts objects, each representing a batch. If has.DQ = TRUE and dqmask exists, each batch will have its own dqmask and dq.lev attributes.

Details

The function computes the number of batches as round(tl(ts) / t_bch) where tl(ts) is the total duration. The time series is evenly split based on index, assuming uniform sampling.

If dqmask is present in the input ts, it is divided row-wise or element-wise depending on its structure, and aligned with the corresponding time range of each batch.

See also

Examples

if (FALSE) { # \dontrun{
batched <- batching(my_ts, t_bch = 2)
length(batched) # number of batches
attr(batched[[1]], "dqmask") # DQ mask for first batch
} # }