Identifies periods of high activity in a time series by analyzing peaks and troughs,
returning a logical vector marking these periods. The function handles special cases
like adjacent peaks and the initial/final sequences.
Usage
classify_high_periods(x, peaks, troughs)
Arguments
- x
numeric vector; the time series values
- peaks
logical vector; same length as x, TRUE indicates peak positions
- troughs
logical vector; same length as x, TRUE indicates trough positions
Value
logical vector; TRUE indicates periods of high activity
Details
The function performs the following steps:
Resolves adjacent peaks by keeping only the highest
Handles the initial sequence before the first trough
Handles the final sequence after the last event
Identifies regions between troughs containing exactly one peak
Examples
if (FALSE) { # \dontrun{
x <- c(1, 3, 2, 1, 4, 2, 1)
peaks <- c(FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE)
troughs <- c(FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE)
classify_high_periods(x, peaks, troughs)
} # }