Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

yearmon

Convert monthly or quarterly data to chron


Description

These functions can be used to convert the times of "ts" series with frequency of 12 or 4 or objects of "yearmon" and "yearqtr" class, as defined in the "zoo" package, to chron dates.

Usage

## S3 method for class 'yearmon'
as.chron(x, frac = 0, holidays = FALSE, ...)
## S3 method for class 'yearqtr'
as.chron(x, frac = 0, holidays = FALSE, ...)
## S3 method for class 'ts'
as.chron(x, frac = 0, holidays = FALSE, ...)

Arguments

x

an object of class "yearmon" or "yearqtr" or "ts" objects, or a numeric vector interpreted “in years” and fractions of years.

frac

Number between zero and one inclusive representing the fraction of the way through the month or quarter.

holidays

If TRUE or a vector of chron dates, indicated holidays and weekends are excluded so the return value will be a non-holiday weekday.

...

Other arguments passed to chron.

Details

The "yearmon" and "yearqtr" classes are defined in package zoo. If holidays is TRUE or a vector of dates then the is.holiday function is used to determine whether days are holidays.

The method for ts objects converts the times corresponding to time(x) to chron. The ts series must have a frequency that is a divisor of 12.

Value

Returns a chron object.

See Also

Examples

## Monthly time series data.
as.chron(AirPassengers)
as.chron(time(AirPassengers))
## convert to first day of the month that is not a weekend or holiday
as.chron(AirPassengers, frac = 0, holidays = TRUE)
## convert to last day of the month
as.chron(AirPassengers, frac = 1)
## convert to last day of the month that is not a weekend or holiday
as.chron(AirPassengers, frac = 1, holidays = TRUE)
## convert to last weekday of the month
as.chron(AirPassengers, frac = 1, holidays = c())

## Quarterly time series data.
as.chron(presidents)
as.chron(time(presidents))

chron

Chronological Objects which can Handle Dates and Times

v2.3-56
GPL-2
Authors
David James [aut] (S original), Kurt Hornik [aut, trl, cre] (<https://orcid.org/0000-0003-4198-9911>), Gabor Grothendieck [ctb], R Core Team [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.