get_week_start: Identify the start of the week for a vector of dates.

Description Usage Arguments Examples

Description

This function returns the date of the start of the week for any given date; "start of the week" is defined as any arbitrary day of the week. Can also calculate the start of the week any number of weeks in the past; I use this while aggregating data for several weeks to ensure that the first week included is always a full week (for example, if I aggregated data for the last eight weeks on a Friday, the week furthest back would only have its Friday data included - if I get_week_start for that date, I ensure the full week's data is aggregated).

Usage

1
2
  get_week_start(dates, start.day = "Monday",
    weeks.back = 0)

Arguments

dates

a vector of dates

start.day

the arbitrary first day of the week - defaults to Monday

weeks.back

how many weeks in the past to evaluate

Examples

1
2
3
4
5
6
7
8
# The start of the current week
get_week_start(Sys.Date())

# Sunday instead of Monday
get_week_start(Sys.Date(), start.day = "Sunday")

# Start of the week eight weeks ago
get_week_start(Sys.Date(), weeks.back = 8)

mmparker/mpmisc documentation built on May 23, 2019, 5:05 a.m.