Learn R Programming

quantmod (version 0.3-3)

breakpoints: Locate Breakpoints by Date

Description

Extract index values of a given zoo object, where the returned index is equal to the last date of each recurring period.

Usage

breakpoints(x, by = c(weekdays, weeks, months, quarters, years),
            ...)

Arguments

x
zoo object with index of class Date
by
period to be indexed from
...
currently unused

Value

  • A numeric vector which can be used to extract rows from the given data object.

Details

Given a zoo object with the appropriate index type, breakpoints will return a numeric vector corresponding to the final rows in each period specified.

For example, by=years would return the index values matching the last observation in each calendar year. Similarly, by=weeks would match the last observations in any given week.

The final index returned corresponds to the last observation in the data object, as this may be useful for calculating values to date.

Examples

Run this code
zoo.data <- zoo(rnorm(31)+10,as.Date(13514:13744,origin="1970-01-01"))
breakpoints(zoo.data,by=weeks)

bp <- breakpoints(zoo.data,by=quarters)
zoo.data[bp]

Run the code above in your browser using DataLab