fin-runlengths: Runlengths of a time series

runlengthsR Documentation

Runlengths of a time series

Description

Computes runlengths of an univariate "timeSeries" object.

Usage

runlengths(x, ...)

Arguments

x

an univariate time series of class "timeSeries".

...

arguments passed to the function na.omit.

Details

Runlengths are defined here as contiguous sequences of values having the same sign.

Zeroes are treated as NAs.

Value

an object of class "timeSeries"

Examples

## random time series - 
   set.seed(4711)
   x <- rnorm(12)
   tS <- timeSeries(data = x, charvec = timeCalendar(), units = "x")
   tS
   
## return runlengths -
   runlengths(tS)

## replace the middle value of the negative stretch of 3 values
tS[5] <- NA
## the two negative values separated by NA are still one run
runlengths(tS)

timeSeries documentation built on Jan. 13, 2024, 8:16 p.m.