ordered_fin_qtr: Create factor variable from financial quarter

View source: R/ordered_fin_qtr.R

ordered_fin_qtrR Documentation

Create factor variable from financial quarter

Description

Creates factor variable from financial quarter to preserve correct ordering in wide reshape of data.

Usage

ordered_fin_qtr(data, quarter_in_long_format)

Arguments

data

A dataframe

quarter_in_long_format

A string variable giving long financial year created using fy_long. Must be quoted.

Value

A dataframe with a new variable 'fin_qtr_ftr'

See Also

fy_long

ordered_m_y

Examples

dat <- data.frame(sample_date = lubridate::dmy("01/01/2001"))
dat$sample_fy <- fy_long(dat$sample_date)
dat <- ordered_fin_qtr(dat, "sample_fy")
class(dat$fin_qtr_ftr)
levels(dat$fin_qtr_ftr)

dat <- data.frame(sample_date = lubridate::dmy("01/01/2001"))
dat$sample_fq <- fq_long(dat$sample_date)
dat <- ordered_fin_qtr(dat, "sample_fq")
class(dat$fin_qtr_ftr)
levels(dat$fin_qtr_ftr)

dat <- data.frame(sample_date = c(lubridate::dmy("01/01/2001"),
   lubridate::dmy("01/04/2001"),
   lubridate::dmy("01/07/2001"),
   lubridate::dmy("01/10/2001"),
   lubridate::dmy("01/01/2002")
   ))
dat$sample_fq <- fq_long(dat$sample_date)
dat <- ordered_fin_qtr(dat, "sample_fq")
class(dat$fin_qtr_ftr)
levels(dat$fin_qtr_ftr)


publichealthengland/hcaidcs documentation built on Jan. 17, 2024, 1:34 p.m.