Convert a date or date-time to an ordered factor of month names
Source:R/date.R
date_month_factor.Rd
date_month_factor()
extracts the month values from a date or date-time and
converts them to an ordered factor of month names. This can be useful in
combination with ggplot2, or for modeling.
Arguments
- x
[Date / POSIXct / POSIXlt]
A date or date-time vector.
- ...
These dots are for future extensions and must be empty.
- labels
[clock_labels / character(1)]
Character representations of localized weekday names, month names, and AM/PM names. Either the language code as string (passed on to
clock_labels_lookup()
), or an object created byclock_labels()
.- abbreviate
[logical(1)]
If
TRUE
, the abbreviated month names fromlabels
will be used.If
FALSE
, the full month names fromlabels
will be used.
Examples
x <- add_months(as.Date("2019-01-01"), 0:11)
date_month_factor(x)
#> [1] January February March April May June July
#> [8] August September October November December
#> 12 Levels: January < February < March < April < May < June < ... < December
date_month_factor(x, abbreviate = TRUE)
#> [1] Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
#> 12 Levels: Jan < Feb < Mar < Apr < May < Jun < Jul < Aug < ... < Dec
date_month_factor(x, labels = "fr")
#> [1] janvier février mars avril mai juin juillet
#> [8] août septembre octobre novembre décembre
#> 12 Levels: janvier < février < mars < avril < mai < juin < ... < décembre