timeSeries (version 4032.109)

aggregate-methods: Aggregate time series

Description

Aggregate a "timeSeries" object over general periods.

Usage

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

Value

an object of class "timeSeries"

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.

See Also

apply, align

Examples

Run this code
## 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)

Run the code above in your browser using DataLab