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

day.of.week

Convert between Julian and Calendar Dates


Description

Utility functions to convert between Julian dates (numbers of days since an origin, by default 1970-01-01) and calendar dates given by year, month, and day within the month.

Usage

## Default S3 method:
julian(x, d, y, origin., ...)
month.day.year(jul, origin.)
leap.year(y)
day.of.week(month, day, year)

Arguments

x, month

vector of month numbers.

d, day

vector of day numbers.

y, year

vector of years.

jul

vector of Julian Dates, i.e., number of days since origin..

origin.

vector specifying the origin as month, day, and year. If missing, it defaults to getOption("chron.origin") if this is non-null, otherwise c(month = 1, day = 1, year = 1970).

...

further arguments to be passed to or from methods.

Value

A vector of Julian dates (number of days since origin.) when julian() is called, or a list with members month, day, year corresponding to the input Julian dates if month.day.year() is called. leap.year() returns a logical vector indicating whether the corresponding year is a leap year. day.of.week() returns a number between 0 and 6 to specify day of the week–0 refers to Sunday.

These functions were taken from Becker, Chambers, and Wilks (1988), and were slightly modified to take chron and dates objects; some also take the extra argument origin..

See Also

Examples

julian(1, 1, 1970)
# [1] 0
unlist(month.day.year(0))
# month   day  year 
#     1     1  1970

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.