An Index Class for Quarterly Data
"yearqtr" is a class for representing quarterly data.
yearqtr(x) as.yearqtr(x, ...) ## S3 method for class 'yearqtr': format(x, format = "\%Y Q\%q", \dots)
yearqtra numeric (interpreted as being
in years). For
as.yearqtranother date class object. For the
formatan object of class
- character string specifying format.
"%q", if present, are replaced with the century, year, last two digits of the year, and quarter (i.e. a number between 1 and 4), respect
- other arguments. Currently not used.
The yearqtr class is used to represent quarterly data. Internally it holds
the data as year plus 0 for Quarter 1, 1/4 for Quarter 2
and so on in order that its internal representation is the same as
ts class with
frequency = 4. If
x is not in this
format it is rounded via
floor(4*x + .0001)/4.
as.yearqtr.character uses a default format of
"%Y q%q" or
"%Y-%q" according to whichever matches.
%q accepts the numbers 1-4 (possibly with leading zeros).
There are coercion methods available for various classes including:
default coercion to
"yearqtr" (which coerces to
and coercion from
"Date" (see below),
as.yearqtrreturn the first argument converted to class
formatmethod returns a character string representation of its argument first argument.
x <- yearqtr(2000 + seq(0, 7)/4) x format(x, "%Y Quarter %q") as.yearqtr("2001 Q2") as.yearqtr("2001 q2") # same as.yearqtr("2001-2") # same # returned Date is the fraction of the way through # the period given by frac (= 0 by default) dd <- as.Date(x) format.yearqtr(dd) as.Date(x, frac = 1) as.POSIXct(x) zz <- zoo(rnorm(8), x, frequency = 4) zz as.ts(zz)