zoo (version 1.2-1)

yearmon: An Index Class for Monthly Data

Description

"yearmon" is a class for representing monthly data.

Usage

yearmon(x)

Arguments

x
numeric (interpreted as being in years).

Value

  • Returns its argument converted to class yearmon.

Details

The yearmon class is used to represent monthly data. Internally it holds the data as year plus 0 for January, 1/12 for February, 2/12 for March and so on in order that its internal representation is the same as ts class with frequency = 12. If x is not in this format it is rounded via floor(12*x + .0001)/12. There are coercion methods available for various classes including: default coercion to "yearmon" (which coerces to "numeric" first) and coercion from "yearmon" to "Date" (see below), "POSIXct", "POSIXlt", "numeric", "character".

See Also

yearqtr, zoo, zooreg, ts

Examples

Run this code
x <- yearmon(2000 + seq(0, 23)/12)
x

# returned Date is the fraction of the way through
# the period given by frac (= 0 by default)
as.Date(x)
as.Date(x, frac = 1)
as.POSIXct(x)

z <- zoo(rnorm(24), x, frequency = 12)
z
as.ts(z)

Run the code above in your browser using DataCamp Workspace