apply.monthly: Apply Function over Calendar Periods

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Apply a specified function to each distinct period in a given time series object.

Usage

1
2
3
4
5
apply.daily(x, FUN, ...)
apply.weekly(x, FUN, ...)
apply.monthly(x, FUN, ...)
apply.quarterly(x, FUN, ...)
apply.yearly(x, FUN, ...)

Arguments

x

an time-series object coercible to xts

FUN

an R function

...

additional arguments to FUN

Details

Simple mechanism to apply a function to non-overlapping time periods, e.g. weekly, monthly, etc. Different from rolling functions in that this will subset the data based on the specified time period (implicit in the call), and return a vector of values for each period in the original data.

Essentially a wrapper to the xts functions endpoints and period.apply, mainly as a convenience.

Value

A vector of results produced by FUN, corresponding to the appropriate periods.

Author(s)

Jeffrey A. Ryan

See Also

endpoints, period.apply, to.monthly

Examples

1
2
3
4
5
6
7
xts.ts <- xts(rnorm(231),as.Date(13514:13744,origin="1970-01-01"))

start(xts.ts)
end(xts.ts)

apply.monthly(xts.ts,mean)
apply.monthly(xts.ts,function(x) var(x))

Example output

Loading required package: zoo

Attaching package: 'zoo'

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric

[1] "2007-01-01"
[1] "2007-08-19"
                  [,1]
2007-01-31  0.21950150
2007-02-28 -0.23485661
2007-03-31 -0.03410866
2007-04-30  0.13983454
2007-05-31 -0.05036995
2007-06-30  0.21637948
2007-07-31 -0.09403144
2007-08-19  0.06142440
                [,1]
2007-01-31 1.3208756
2007-02-28 0.9985181
2007-03-31 0.8849621
2007-04-30 0.8870611
2007-05-31 0.7286655
2007-06-30 0.9920177
2007-07-31 1.1313456
2007-08-19 1.1064541

xts documentation built on Dec. 23, 2017, 5:30 p.m.