yearmonth {tsibble} | R Documentation |
Represent year-month
Description
Create or coerce using yearmonth()
.
Usage
yearmonth(x, ...)
make_yearmonth(year = 1970L, month = 1L)
## S3 method for class 'character'
yearmonth(x, format = NULL, ...)
is_yearmonth(x)
Arguments
x |
Other object. |
... |
Further arguments to methods. |
year , month |
A vector of numerics give years and months. |
format |
A vector of strings to specify additional formats of |
Value
year-month (yearmonth
) objects.
Display
Use format()
to display yearweek
, yearmonth
, and yearquarter
objects
in required formats.
Please see strptime()
details for supported conversion specifications.
See Also
scale_x_yearmonth and others for ggplot2 scales
Other index functions:
yearquarter()
,
yearweek()
Examples
# coerce POSIXct/Dates to yearmonth
x <- seq(as.Date("2016-01-01"), as.Date("2016-12-31"), by = "1 month")
yearmonth(x)
# parse characters
yearmonth(c("2018 Jan", "2018-01", "2018 January"))
# seq() and arithmetic
mth <- yearmonth("2017-11")
seq(mth, length.out = 10, by = 1) # by 1 month
mth + 0:9
# display formats
format(mth, format = "%y %m")
# units since 1970 Jan
as.double(yearmonth("1969 Jan") + 0:24)
make_yearmonth(year = 2021, month = 10:11)
make_yearmonth(year = 2020:2021, month = 10:11)
[Package tsibble version 1.1.5 Index]