stats-aggregate: Aggregate time series

aggregate-methodsR Documentation

Aggregate time series

Description

Aggregate a "timeSeries" object over general periods.

Usage

## S4 method for signature 'timeSeries'
aggregate(x, by, FUN, ...)

Arguments

x

an object of class "timeSeries".

by

a sequence of "timeDate" objects denoting the aggregation periods, see section ‘Details’.

FUN

the function to be applied.

...

arguments passed to other methods.

Details

aggregate aggregates x by applying FUN on the values of the time series in each of the aggregation periods, specified by argument by.

Argument by should be of the same class as time(x). by is sorted and duplicated values are removed from it. Each pair of consecutive values in by then determines a period over which to apply the aggregation function FUN, see findInterval.

Value

an object of class "timeSeries"

See Also

apply, align

Examples

## Load Microsoft Data Set -
   x <- MSFT

## Aggregate by Weeks - 
   by <- timeSequence(from = start(x),  to = end(x), by = "week")
   aggregate(x, by, mean)

## Aggregate to Last Friday of Month -
   by <- unique(timeLastNdayInMonth(time(x), 5))
   X <- aggregate(x, by, mean)
   X
   dayOfWeek(time(X))
   isMonthly(X)

## Aggregate to Last Day of Quarter -
   by <- unique(timeLastDayInQuarter(time(x)))
   X <-  aggregate(x, by, mean)
   X
   isQuarterly(X)

timeSeries documentation built on Sept. 30, 2024, 9:15 a.m.