rolling_apply_specialized: Apply Rolling Function (Specialized Implementation)

Description Usage Arguments Details Methods (by class) References Examples

View source: R/rolling_apply_specialized.R

Description

This function provides a fast, specialized implementation of rolling_apply for certain choices of FUN and for by=NULL (i.e. when moving the rolling time window one observation at a time, rather than by a fixed temporal amount).

Usage

1
2
3
4
5
rolling_apply_specialized(x, ...)

## S3 method for class 'uts'
rolling_apply_specialized(x, width, FUN, align = "right",
  interior = FALSE, ...)

Arguments

x

a numeric time series object with finite, non-NA observation values.

width

a finite, positive duration object, specifying the temporal width of the rolling time window.

FUN

a function to be applied to the vector of observation values inside the half-open (open on the left, closed on the right) rolling time window.

align

either "right", "left", or "center". Specifies the alignment of each output time relative to its corresponding time window. Using "right" gives a causal (i.e. backward-looking) time series operator, while using "left" gives a purely forward-looking time series operator.

interior

logical. Should time windows lie entirely in the interior of the temporal support of x, i.e. inside the time interval [start(x), end(x)]?

...

further arguments passed to or from methods.

Details

It is usually not necessary to call this function, because it is called automatically by rolling_apply whenever a specialized implementation is available.

Methods (by class)

References

Eckner, A. (2017) Algorithms for Unevenly Spaced Time Series: Moving Averages and Other Rolling Operators.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
rolling_apply_specialized(ex_uts(), dhours(12), FUN=length)
rolling_apply_specialized(ex_uts(), dhours(12), FUN=length, align="center")
rolling_apply_specialized(ex_uts(), dhours(12), FUN=length, align="left")

rolling_apply_specialized(ex_uts(), dhours(12), FUN=length)
rolling_apply_specialized(ex_uts(), dhours(12), FUN=length, interior=TRUE)

# Rolling sum
rolling_apply_specialized(ex_uts(), ddays(1), FUN=sum)
rolling_apply_specialized(ex_uts(), ddays(1), FUN=sum) - rolling_apply(ex_uts(), ddays(1), FUN=sum)

# Rolling min/max
rolling_apply_specialized(ex_uts(), ddays(1), FUN=min)
rolling_apply_specialized(ex_uts(), ddays(1), FUN=max)

# Rolling prodcut
rolling_apply_specialized(ex_uts(), ddays(0.5), FUN=prod)

andreas50/utsOperators documentation built on May 25, 2019, 7:16 a.m.