timeSeries (version 4032.109)

runlengths: Runlengths of a time series

Description

Computes runlengths of an univariate "timeSeries" object.

Usage

runlengths(x, ...)

Value

an object of class "timeSeries"

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.

Examples

Run this code
## 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)

Run the code above in your browser using DataLab