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

days

Return Various Periods from a Chron or Dates Object


Description

Given a chron or dates object, extract the year, quarter, month, day (within the month) or weekday (days within the week) of the date it represents.

Usage

days(x)
## Default S3 method:
weekdays(x, abbreviate = TRUE)
## Default S3 method:
months(x, abbreviate = TRUE)
## Default S3 method:
quarters(x, abbreviate = TRUE)
years(x)

Arguments

x

an object inheriting from class "dates", or coercible to such via as.chron.

abbreviate

should abbreviated names be returned? Default is TRUE.

Details

Note that months, quarters and weekdays are generics defined in package base which also provides methods for objects of class "Date" as generated, e.g., by Sys.Date. These methods return character rather than factor variables as the default methods in chron do. To take advantage of the latter, Date objects can be converted to dates objects using as.chron, see the examples.

Value

an ordered factor corresponding to days, weekdays, months, quarters, or years of x for the respective function.

See Also

Examples

dts <- dates("07/01/78") + trunc(50 * rnorm(30))
plot(weekdays(dts))
plot(months(dts))

## The day in the current timezone as a Date object.
Dt <- Sys.Date()
## Using the months method for Date objects.
months(Dt)
## Using the months default method.
months(as.chron(Dt))

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.