aggregate-methods
From timeSeries v3022.101.2
by Tobias Setz
timeSeries Class, Functions and Methods
Aggregates a 'timeSeries' Object.
Usage
"aggregate"(x, by, FUN, ...)
daily2monthly(x, init=FALSE)
daily2weekly(x, startOn="Tue", init=FALSE)
Arguments
- x
- an object of class 'timeSeries'.
- by
-
a sequence of
timeDate
objects denoting the aggregation period. - FUN
- the function to be applied.
- startOn
-
a string value, specifying the day of week as a three
letter abbreviation. Weekly aggregated data records
are then fixed to the weekdays given by the argument
startOn
. - init
-
a logical value, if set to
TRUE
then the time series will be indexed to 1 for its first value. By default init is set toFALSE
. - ...
- arguments passed to other methods.
Details
The function aggregate
is a function which can
aggregate time series on general aggregation periods.
In addition there are two tailored function for simple
usage: Function daily2monthly
and daily2weekly
which allow to aggregate 'timeSeries' objects from daily
to monthly or weekly levels, respectively.
In the case of the function daily2weekly
one can
explicitely the starting day of the week, the default
value is Tuesday, startOn="Tue"
.
Value
aggregate
returns an aggregated S4 object of class
timeSeries
.daily2monthly
returns an aggregated monthly object
of class timeSeries
.daily2weekly
returns an aggregated weekly object
of class timeSeries
starting on the specified day
of week.Examples
library(timeSeries)
## 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)
## Aggregate daily records to end of month records -
X <- daily2monthly(x)
X
isMonthly(X)
## Aggregate da, ily records to end of week records -
X <- daily2weekly(x, startOn="Fri")
X
dayOfWeek(time(X))
Community examples
Looks like there are no examples yet.