
Compute consecutive run lengths for flatline detection
Source:R/utilASRflagrleflat.R
utilASRflagrleflat.RdCompute consecutive run lengths for flatline detection
Details
For each position \(i\), the run extends only when adding the
current observation to the run keeps the range (max minus min of all
values in the run) strictly \(<\) delta. This prevents both
large single-step jumps and slow cumulative drift from accumulating run
length. A range equal to delta is not considered flatline.
A run length of 1 means the observation is not part of a flat stretch.
NA values in vals break the run.
Examples
vals <- c(10, 10, 10.005, 10.003, 12, 12, 12)
utilASRflagrleflat(vals, delta = 0.01)
#> [1] 1 2 3 4 1 2 3