calendrical-computations: Calendrical Computations in 'tind' Package

calendrical-computationsR Documentation

Calendrical Computations in tind Package

Description

The following functions can be used for calendrical computations, especially determining dates of movable observances. All function are vectorised.

nth_day_of_year returns the date of the nth day of a year.

last_day_in_month and last_day_in_quarter return the date of the last day in a month or a quarter.

nth_dw_in_month returns the date of the nth day of week in a month.

last_dw_in_month returns the date of the last day of week in a month.

easter returns the date of Easter in a year.

Usage

nth_day_of_year(nth, y)

last_day_in_month(m)

last_day_in_quarter(q)

nth_dw_in_month(nth, dw, m)

last_dw_in_month(dw, m)

easter(y)

Arguments

nth

a numeric value or vector of indices (1–366 for nth_day_of_year, 1–5 for nth_dw_in_month).

y, q, m

an object of tind class or an R object coercible to it.

dw

a numeric value or vector of days of week (values in range 1–7 with Monday as the 1st day).

Value

An object of tind class with dates (type "d").

See Also

time-index-components, time-index-properties, Ops. Further examples of application of these functions can be found in calendar documentation. For calendrical computations involving business days see bizday.

Examples

# Thanksgiving in the US is observed on the fourth Thursday of November,
# which in 2019 was on:
nth_dw_in_month(4, 4, 201911)
# and Black Friday?
nth_dw_in_month(4, 4, 201911) + 1

# Daylight Saving Time in the EU in 2019 began on the last Sunday in March,
# which was on:
last_dw_in_month(7, 201903)

# International Monetary Market dates in 2022 - 3rd Wednesday
# of March, June, September, and December
nth_dw_in_month(3, 3, tind(y = 2022, m = 3 * 1:4))

# determine frequencies of Easter months over the last 100 years
# Easter months
em <- month(easter(as.year(today()) + (-99:0)), labels = TRUE)
# table and barplot
table(em) / length(em) * 100
if (require("graphics", quietly = TRUE)) {
    barplot(table(em) / length(em) * 100, ylim = c(0, 100), col = "#faf06d")
}


tind documentation built on Dec. 28, 2025, 1:06 a.m.