padr (version 0.6.2)

closest_weekday: Retrieve the closest given weekday

Description

Find the closest instance of the requested weekday to min(x). Helper function for thicken with the interval "week", when the user desires the start day of the weeks to be different from Sundays.

Usage

closest_weekday(x, wday = 1, direction = c("down", "up"))

Value

Object of class Date, reflecting the closest desired weekday to x.

Arguments

x

A vector of class Date, POSIXct, or POSIXlt.

wday

Integer in the range 0-6 specifying the desired weekday start (0 = Sun, 1 = Mon, 2 = Tue, 3 = Wed, 4 = Thu, 5 = Fri, 6 = Sat).

direction

The first desired weekday before ("down") or after ("up") the first day in x.

Examples

Run this code
closest_weekday(coffee$time_stamp)
closest_weekday(coffee$time_stamp, 5)
closest_weekday(coffee$time_stamp, 1, direction = "up")
closest_weekday(coffee$time_stamp, 5, direction = "up")

Run the code above in your browser using DataLab