weekIndex: Generate an index of weeks

View source: R/timeIndices.R

weekIndexR Documentation

Generate an index of weeks

Description

Function to create a week index variable with weeks determined as defined in ISO 8601. If the week (starting on Monday) containing 1 January has four or more days in the new year, then it is considered week 1. Otherwise, it is the 53rd week of the previous year, and the next week is week 1.

Usage

weekIndex(x)

Arguments

x

A vector of dates

Examples

# given a vector of dates
df <- data.frame(date = as.Date(c("2016-12-20","2016-12-27","2017-01-01","2017-01-07"),
format = "%Y-%m-%d"))
# calculate the time period variable
df$period <- weekIndex(df$date)
df

IndexNumR documentation built on Nov. 11, 2023, 1:07 a.m.