Learn R Programming

xts (version 0.14.1)

period.sum: Optimized Calculations By Period

Description

Calculate a sum, product, minimum, or maximum for each non-overlapping period specified by INDEX.

Usage

period.sum(x, INDEX)

period.prod(x, INDEX)

period.max(x, INDEX)

period.min(x, INDEX)

Value

An xts or zoo object containing the sum, product, minimum, or maximum for each endpoint in INDEX.

Arguments

x

A univariate data object.

INDEX

A numeric vector of endpoints for each period.

Author

Jeffrey A. Ryan

Details

These functions are similar to calling period.apply() with the same endpoints and function. There may be slight differences in the results due to numerical accuracy.

For xts-coercible objects, an appropriate INDEX can be created by a call to endpoints().

See Also

endpoints(), period.apply()

Examples

Run this code

x <- c(1, 1, 4, 2, 2, 6, 7, 8, -1, 20)
i <- c(0, 3, 5, 8, 10)

period.sum(x, i)
period.prod(x, i)
period.min(x, i)
period.max(x, i)

data(sample_matrix)
y <- sample_matrix[, 1]
ep <- endpoints(sample_matrix)

period.sum(y, ep)
period.sum(as.xts(y), ep)

period.prod(y, ep)
period.prod(as.xts(y), ep)

period.min(y, ep)
period.min(as.xts(y), ep)

period.max(y, ep)
period.max(as.xts(y), ep)

Run the code above in your browser using DataLab