Aggregation and coursening of time series and signals.
This is the method for the aggregate function for objects of class
timeSeries and signalSeries.
aggregateSeries(x, pos, FUN, moving=FALSE, together=FALSE, drop.empty=TRUE,
include.ends=FALSE, adj, offset, colnames, by, k.by=1,
week.align=NULL, holidays=timeDate(), align.by=TRUE,
incr=1, ...)returns a new time series whose positions are the adjusted passed-in positions or
positions generated from by, k.by, and so on,
(or possibly a subset if drop.empty is TRUE) and whose
rows are aggregated from x as specified in the arguments.
Aggregation takes place by separating x into blocks separated by the positions
(or overlapping blocks with a fixed number of samples if moving is
supplied), and then applying FUN to each column (or all columns
together if together is TRUE) and forming a new time series with
the positions and aggregated data.
the series object to be aggregated.
the break positions for aggregation (can also be supplied in the by
argument if desired).
the function to use for aggregation. Often mean, sum, or hloc.
If moving is FALSE,
FUN can also be a character string like "fastFFF",
to aggregate column-wise using the corresponding fast
igroupFFF function. (The together argument is ignored.)
Possible choices for FFF are currently
Means, Maxs, Mins, Sums, Prods,
Anys, and Alls.
either FALSE to do standard aggregation,
or a positive integer N to perform a moving aggregation
(normally used for a moving average) over N samples.
a logical value. if TRUE, passes all columns of x together into FUN;
If FALSE (the default), passes each column separately into FUN
for each aggregation block.
a logical value. If TRUE (the default), drops aggregation blocks with
no positions to aggregate from the output.
a logical value. If TRUE, includes the positions before the first
given aggregation block and after the last in the first/last blocks.
If FALSE (the default), does not include those positions in the output.
if provided, adjusts the positions of the output series so that they lie a
fraction adj towards the blocks ending position. The default is to use
the lower end of the block for the output position. 0.5 uses the
center of the aggregation block for the output position, and 1.0
uses the upper end of the block.
as an alternative to adj, provide a constant offset to add
to the lower end of the aggregation block to get the output series
positions. For instance, in monthly aggregation, you might supply
an offset of 9 days so that the output positions fell on the tenth of
each month.
new column names for the output series. The default is to use the same names as the input series if the output series has the same width.
if pos is missing and by is supplied for aggregating
calendar-based time series, new positions are generated as a regular
time/date sequence using by, k.by, week.align,
and holidays.
by gives the spacing between successive values in the sequence.
This can be a timeSpan, timeRelative, or numeric value,
in which case k.by is ignored.
Alternatively, it can be one of the following character strings:
"milliseconds"
"seconds"
"minutes"
"hours"
"days"
"weekdays"
"bizdays"
"weeks"
"months"
"quarters"
"years"
giving the time units of intervals between values in the sequence.
a non-zero integer giving the width of the interval between consecutive
values in the sequence in terms of the units given in by. Ignored if
by is not a character string or if pos is given.
if not NULL and by is "weeks",
you can supply a character
string (or a number, 0 to 6 with 0 being Sunday)
to specify a weekday to use for aggregation. The character string must
be sufficient to make a unique case-insensitive match to the strings
in timeSeriesOptions("time.day.name"). Ignored if
by is not a character string or pos is given.
holidays for business day sequences. (Ignored if by is not
a character string or pos is given.)
a logical value. If TRUE (the default), adjusted the sequence so that each element is on a whole number
of the by * k.by units. For example, if the units are 2 months, make the sequence
be only on the first of January, March, and so on. Ignored if
by is not a character string.
For moving aggregation, the moving window moves forward by this many steps in the time series, for each window.
Additional arguments to pass to FUN.
timeSeries, signalSeries,
align, aggregate
x <- timeSeries(data.frame(1:20,rnorm(20)), timeCalendar(d=1:20))
aggregate(x, FUN=mean, by="weeks")
Run the code above in your browser using DataLab