View source: R/time_categories.R
mmyy | R Documentation |
This function defines month-year categories from time series (i.e., Date
and DateTimeClasses
objects).
mmyy(x, levels = TRUE)
x |
An vector of class |
levels |
A logical input which defines whether or not to return a factor with chronologically ordered levels (i.e., levels ordered by year then month, for the inputted |
The function returns a vector which specifies the month and year of each observation in x
as mm-yyyy. By default (i.e., when levels = TRUE
), this is a factor with chronologically ordered levels (i.e., levels ordered by year then month, for the inputted x
). If levels = FALSE
, a character vector is returned.
Edward Lavender
#### Example (1): Extract the month-year category from Dates: mmyy(as.Date("2016-01-01")) mmyy(seq.Date(as.Date("2016-01-01"), as.Date("2016-12-01"), 10)) #### Example (2): Extract the month-year category from POSIXct objects: mmyy(as.POSIXct("2016-01-01")) mmyy(seq.POSIXt(as.POSIXct("2016-01-01"), as.POSIXct("2016-12-01"), "20 days")) #### Example (3): By default, mmyy() returns an ordered factor # ... with levels ordered chronologically: mmyy(c(as.POSIXct(c("2017-01-02", "2016-01-02", "2016-03-01", "2017-02-03")))) #### Example (4): Ordered levels can be suppressed with levels = FALSE, # ... in which case a character vector is returned: mmyy(as.Date("2016-01-01"), levels = FALSE) mmyy(seq.Date(as.Date("2016-01-01"), as.Date("2016-12-01"), 10), levels = FALSE) mmyy(as.POSIXct("2016-01-01"), levels = FALSE) mmyy(seq.POSIXt(as.POSIXct("2016-01-01"), as.POSIXct("2016-12-01"), "20 days"), levels = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.