closest_weekday: Retrieve the closest given weekday

View source: R/closest_weekday.R

closest_weekdayR Documentation

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"))

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.

Value

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

Examples

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")

padr documentation built on Nov. 23, 2022, 5:06 p.m.