# NOT RUN {
# coerce POSIXct/Dates to yearweek, yearmonth, yearquarter ----
x <- seq(as.Date("2016-01-01"), as.Date("2016-12-31"), by = "1 month")
yearweek(x)
yearmonth(yearweek(x)); yearmonth(x)
yearquarter(x)
# coerce numerics to yearmonth, yearquarter ----
yearmonth(seq(2010, 2017, by = 1 / 12))
yearquarter(seq(2010, 2017, by = 1 / 4))
# coerce yearmonths to yearquarter ----
y <- yearmonth(x)
yearquarter(y)
# S3 method seq() ----
wk1 <- yearweek(as.Date("2017-11-01"))
wk2 <- yearweek(as.Date("2018-04-29"))
seq(from = wk1, to = wk2, by = 2) # by two weeks
mth <- yearmonth(as.Date("2017-11-01"))
seq(mth, length.out = 5, by = 1) # by 1 month
seq(yearquarter(mth), length.out = 5, by = 1) # by 1 quarter
# }
Run the code above in your browser using DataLab