weekIndex: Generate an index of weeks

Description Usage Arguments Examples

View source: R/timeIndices.R

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

1

Arguments

x

A vector of dates

Examples

1
2
3
4
5
6
# 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 July 21, 2021, 5:08 p.m.