Create auxiliar variables for a date variable
dttm_vars.Rd
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.
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
Examples
df <- data.frame(dt = lubridate::dmy("01/01/01"))
#without prefix
dplyr::glimpse(dttm_vars(df,dt))
#> Rows: 1
#> Columns: 12
#> $ dt <date> 2001-01-01
#> $ mon_abb <ord> Jan
#> $ mon_lbl <ord> January
#> $ mon_num <dbl> 1
#> $ day_num <int> 1
#> $ year_num <dbl> 2001
#> $ year_lbl <fct> 2001
#> $ week_num <dbl> 1
#> $ epiweek_num <dbl> 1
#> $ isoweek_num <dbl> 1
#> $ wday_abb <ord> Mon
#> $ wday_lbl <ord> Monday
#with prefix
dplyr::glimpse(dttm_vars(df,dt,"dt"))
#> Rows: 1
#> Columns: 12
#> $ dt <date> 2001-01-01
#> $ dt_mon_abb <ord> Jan
#> $ dt_mon_lbl <ord> January
#> $ dt_mon_num <dbl> 1
#> $ dt_day_num <int> 1
#> $ dt_year_num <dbl> 2001
#> $ dt_year_lbl <fct> 2001
#> $ dt_week_num <dbl> 1
#> $ dt_epiweek_num <dbl> 1
#> $ dt_isoweek_num <dbl> 1
#> $ dt_wday_abb <ord> Mon
#> $ dt_wday_lbl <ord> Monday