period_math: Optimized Calculations By Period

period.sumR Documentation

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)

Arguments

x

A univariate data object.

INDEX

A numeric vector of endpoints for each period.

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().

Value

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

Author(s)

Jeffrey A. Ryan

See Also

endpoints(), period.apply()

Examples


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)


xts documentation built on Oct. 16, 2024, 1:08 a.m.