Learn R Programming

IndexNumR (version 0.6.0)

yearIndex: Generate an index of years

Description

Function to create a year index variable

Usage

yearIndex(x)

Arguments

x

A vector or column of dates

Examples

Run this code
# given a vector of dates
df <- data.frame(date = as.Date(c("2017-01-01","2018-04-01","2019-07-01","2019-08-01"),
format = "%Y-%m-%d"))
# calculate the time period variable
df$period <- yearIndex(df$date)
df

Run the code above in your browser using DataLab