last_weekday {datetimeutils} | R Documentation |
Functions for Computing Days of the Week
Description
Functions for computing a specifed day-of-week, such as ‘the last Friday of October 2015’.
Usage
last_weekday(weekday, x, shift = 0L,
period = "month", before, inclusive = TRUE)
nth_weekday(weekday, x, n = 1L)
Arguments
x |
a vector of class |
shift |
a vector of integers |
weekday |
an integer ( |
period |
character. Currently ignored. |
before |
a |
inclusive |
logical. Is |
n |
an integer |
Details
last_weekday
computes the last day-of-the-week
(specified as an integer 0 to 6, with Sunday being 0)
in a given month, e.g. ‘the last Friday’.
shift
moves forward (when positive) or
backward (when negative) by one week; see Examples.
nth_weekday
gives the n-th
day-of-the-week (specified as an integer 0 to 6, with
Sunday being 0) of a given month, e.g. ‘the
second Monday’.
Value
Date
Author(s)
Enrico Schumann
References
B.D. Ripley and K. Hornik. Date-Time Classes. R-News, 1(2):8–12, 2001.
See Also
Many useful functions are also in package chron.
Examples
## GOAL: find the third Friday in March 2013
## SOLUTION: find the last Friday in February 2013 and
## shift forward by 3 weeks
last_weekday(5, as.Date("2013-02-01"), shift = 3)
## ... or much simpler
nth_weekday(5, as.Date("2013-03-01"), 3)