break positions for aggregation (can also be supplied in the
by
argument if desired).
FUN
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.
OPTIONAL ARGUMENTS:
moving
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.
together
if
TRUE, pass all columns of
x together into
FUN; default is to pass
each column separately into
FUN for each aggregation block.
drop.empty
logical value telling whether or not to drop aggregation blocks with
no positions to aggregate from the output (default is to drop them).
include.ends
logical value telling whether to include positions before the first
given aggregation block and after the last in the first/last blocks;
default would not include those positions in the output at all.
adj
if provided, adjust the positions of the output series so that they lie a
fraction
adj towards the blocks ending position; default is to use
the lower end of the block for the output position. 0.5 would use the
center of the aggregation block for the output position, and 1.0 would
use the upper end of the block.
offset
as an alternative to
adj, you can 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.
colnames
new column names for the output series. Default is to use the same
names as the input series if the output series has the same width.
by
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",
or
"years", giving the time units of intervals between values in
the sequence.
k.by
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.
week.align
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
options("time.day.name"). Ignored if
by is not a character string or
pos is given.
holidays
holidays for business day sequences (ignored if
by is not
a character string or
pos is given).
align.by
if
T, adjust the sequence so that each element is on a whole number
of the
by * k.by units; e.g., if the units are 2 months, make the sequence
be only on the first of January, March, etc. Ignored if
by is not a character string. Note that in
contrast to other series functions, the default value of this argument is T.
incr
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.
VALUE:
a new time series whose positions are the adjusted passed-in positions or
positions generated from
by,
k.by etc.
(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.
SEE ALSO:
,
,
,
,
.
EXAMPLES:
x <- timeSeries(data.frame(1:20,rnorm(20)), timeCalendar(d=1:20))
aggregate(x, FUN=mean, by="weeks")
aggregate(x, FUN="fastMeans", by="weeks")