dttm_vars: Create auxiliar variables for a date variable

View source: R/dttm_vars.r

dttm_varsR Documentation

Create auxiliar variables for a date variable

Description

Computation of auxiliar date variables:

- mon_abb: a factor with the abbreviated name of the month;
- mon_lbl: a factor with the complete name of the month;
- mon_num: the number of the month;
- day_num: the number of the day within the month;
- year_num: the number of the year;
- year_lbl: the number of the year, bu as a factor;
- week_num: the number of complete seven day periods that have occurred between the date and January 1st, plus one;
- epiweek_num: the US CDC version of epidemiological week. Starts on Sunday;
- isoweek_num: the week as it would appear in the ISO 8601 system, which uses a reoccurring leap week. Starts on Monday;
- wday_abb: a factor with the week day abbreviated name;
- wday_lbl: a factor with the week day complete name.

Usage

dttm_vars(df, dt_var, prefix = NULL)

Arguments

df

A single data.frame

dt_var

A date variable from a data.frame

prefix

A character single value (default = NULL), that that will be added as the prefix for the computed variables

Value

A tibble with the original data and the new computed variables.

Examples


df <- data.frame(dt = lubridate::dmy("01/01/01"))

#without prefix
dplyr::glimpse(dttm_vars(df,dt))

#with prefix
dplyr::glimpse(dttm_vars(df,dt,"dt"))


vbfelix/relper documentation built on May 10, 2024, 10:50 p.m.