An Index Class for Quarterly Data

"yearqtr" is a class for representing quarterly data.

as.yearqtr(x, ...)
## S3 method for class 'yearqtr':
format(x, format = "\%Y Q\%q", \dots)
for yearqtr a numeric (interpreted as being in years). For as.yearqtr another date class object. For the "yearqtr" method of format an object of class "yearqtr"
character string specifying format. "%C", "%Y", "%y" and "%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", "%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 "numeric" first) and coercion from "yearqtr" to "Date" (see below), "POSIXct", "POSIXlt", "numeric", "character" and "jul". The last one is from the frame package on CRAN. There is an is.numeric method which returns FALSE. There is also a date method for as.yearqtr usable with objects created with package date. Sys.yearqtr() returns the current year/month and methods for min, max and range are defined (by defining a method for Summary. A yearqtr mean method is also defined. Certain methods support a frac argument. See yearmon.


  • yearqtr and as.yearqtr return the first argument converted to class yearqtr. The format method returns a character string representation of its argument first argument.

See Also

yearmon, zoo, zooreg, ts, strptime.

  • yearqtr
  • as.yearqtr
  • as.yearqtr.default
  • as.yearqtr.numeric
  • as.yearqtr.integer
  • as.yearqtr.dates
  • as.yearqtr.Date
  • as.yearqtr.timeDate
  • as.yearqtr.jul
  • as.yearqtr.POSIXt
  • as.yearqtr.character
  • as.yearqtr.factor
  • as.yearqtr.yearqtr
  • as.Date.yearqtr
  • as.POSIXct.yearqtr
  • as.POSIXlt.yearqtr
  • as.list.yearqtr
  • as.numeric.yearqtr
  • as.character.yearqtr
  • c.yearqtr
  • cycle.yearqtr
  • format.yearqtr
  • is.numeric.yearqtr
  • mean.yearqtr
  • print.yearqtr
  • range.yearqtr
  • summary.yearqtr
  • unique.yearqtr
  • [.yearqtr
  • [[.yearqtr
  • MATCH.yearqtr
  • Ops.yearqtr
  • Summary.yearqtr
  • Sys.yearqtr
  • -.yearqtr
  • xtfrm.yearqtr
x <- as.yearqtr(2000 + seq(0, 7)/4)

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)
as.Date(x, frac = 1)

zz <- zoo(rnorm(8), x, frequency = 4)
Documentation reproduced from package zoo, version 1.7-12, License: GPL-2 | GPL-3

Community examples

Looks like there are no examples yet.