Learn R Programming

quantmod (version 0.2-5)

period.apply: Apply Function Over Specified Interval

Description

Apply a specified function to data over a given interval, where the interval is taken to be the data from INDEX[k] to INDEX[k+1], for k=1:length(INDEX).

Usage

period.apply(x, INDEX, FUN, ...)

Arguments

x
data to apply FUN to
INDEX
numeric vector specifying indexing
FUN
an argument of type function
...
additional arguments for FUN

Value

  • A numeric vector with length INDEX

Details

Similar to the rest of the apply family, calculate a specified functions value given a shifting set of data values.

Useful for applying arbitrary functions over time, as when INDEX is the result of a call to breakpoints.

See Also

breakpoints apply.monthly

Examples

Run this code
zoo.data <- zoo(rnorm(31)+10,as.Date(13514:13744,origin="1970-01-01"))
bp <- breakpoints(zoo.data,by=weeks)
period.apply(zoo.data, INDEX=bp, FUN=function(x) sd(x))
period.apply(zoo.data, INDEX=bp, FUN=sd)                  #same

Run the code above in your browser using DataLab