# 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)
Run the code above in your browser using DataLab