Learn R Programming

dataPreparation (version 1.1.1)

build_date_factor: Date Factor

Description

Map a vector of dates to a factor at one of these levels "yearmonth", "yearquarter", "quarter", "month"

Usage

build_date_factor(data_set, type = "yearmonth")

Arguments

data_set

A vector of date values

type

One of "year", "yearquarter", "yearmonth", "quarter", "month"

Details

The resulting vector is an ordered factor of the specified type (e.g. yearmonth)

Examples

Run this code
library(data.table)
data_set <- as.Date(c("2014-01-01", "2015-01-01", "2015-06-01"))
build_date_factor(data_set, type = "yearmonth")
build_date_factor(data_set, type = "yearquarter")
build_date_factor(data_set, type = "yearquarter")

Run the code above in your browser using DataLab