R: Calculate Sum By Period

period.sum {xts} | R Documentation

## Calculate Sum By Period

### Description

Calculate a sum for each period of INDEX. Essentially a rolling application of sum over a series of non-overlapping sections.

### Usage

    period.sum(x, INDEX)

### Arguments

`x` | a univariate data object
`INDEX` | a numeric vector of endpoints to calculate sum on

### Details

Used to calculate a sum per period given an arbitrary index of sections to be calculated over. This is an optimized function for sum. There are additionally optimized versions for min, max, and prod.

For xts-coercible objects, an appropriate INDEX can be derived from a call to `endpoints`.

### Value

An `xts` or `zoo` object of sums, indexed by the period endpoints.

### Author(s)

Jeffrey A. Ryan

### See Also

`endpoints`, `period.max`, `period.min`, `period.prod`

### Examples

    period.sum(c(1,1,4,2,2,6,7,8,-1,20),c(0,3,5,8,10))

    data(sample_matrix)
    period.sum(sample_matrix[,1],endpoints(sample_matrix))
    period.sum(as.xts(sample_matrix)[,1],endpoints(sample_matrix))

[Package xts version 0.12.1 Index]