The as.POSIXlt
function delivers a list that can be extracted to give numeric month values that are C-like in that they begin with 0 for January. That should not be a problem for splitting. See the Details section for options, but I can tell you there is not a quarterly option.
Here is the code for delivering weeks:
as.POSIXlt( Sys.Date()+1:60 )$yday %/% 7
[1] 13 13 13 13 13 14 14 14 14 14 14 14 15 15 15 15 15 15 15 16 16 16 16 16 16 16 17 17 17 17
[31] 17 17 17 18 18 18 18 18 18 18 19 19 19 19 19 19 19 20 20 20 20 20 20 20 21 21 21 21 21 21
But do notice that this will not necessarily be aligned with your choice of the weeks' beginning. You might need to subtract the numeric weekday of the first of the year to get it to align properly. (Sunday is the 0 weekday.)
as.POSIXlt( Sys.Date()+1:60 - as.POSIXlt( as.Date( paste0( format(Sys.Date(), "%Y"),"-01-01")))$wday )$yday %/% 7
[1] 13 13 13 13 13 13 14 14 14 14 14 14 14 15 15 15 15 15 15 15 16 16 16 16 16 16 16 17 17 17
[31] 17 17 17 17 18 18 18 18 18 18 18 19 19 19 19 19 19 19 20 20 20 20 20 20 20 21 21 21 21 21
Another option that delivers a printable label, zoo::as.yearmon
.
as.POSIXlt( Sys.Date()+1:60 )$mon
[1] 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
[46] 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5
zoo::as.yearmon( Sys.Date()+1:60 )
[1] "Apr 2018" "Apr 2018" "Apr 2018" "Apr 2018" "Apr 2018" "Apr 2018" "Apr 2018" "Apr 2018"
[9] "Apr 2018" "Apr 2018" "Apr 2018" "Apr 2018" "Apr 2018" "Apr 2018" "Apr 2018" "Apr 2018"
[17] "Apr 2018" "Apr 2018" "Apr 2018" "Apr 2018" "Apr 2018" "Apr 2018" "Apr 2018" "Apr 2018"
[25] "Apr 2018" "Apr 2018" "Apr 2018" "May 2018" "May 2018" "May 2018" "May 2018" "May 2018"
[33] "May 2018" "May 2018" "May 2018" "May 2018" "May 2018" "May 2018" "May 2018" "May 2018"
[41] "May 2018" "May 2018" "May 2018" "May 2018" "May 2018" "May 2018" "May 2018" "May 2018"
[49] "May 2018" "May 2018" "May 2018" "May 2018" "May 2018" "May 2018" "May 2018" "May 2018"
[57] "May 2018" "May 2018" "Jun 2018" "Jun 2018"
The zoo package also has an as.yearqtr
function:
zoo::as.yearqtr( Sys.Date()+seq(0, 180, by=30) )
#[1] "2018 Q2" "2018 Q2" "2018 Q2" "2018 Q3" "2018 Q3" "2018 Q3" "2018 Q3"
"Under the hood" (or "bonnet" as the case may be) this function is actually delivering numeric values as well but with a class that has a special print method:
unclass( zoo::as.yearqtr( Sys.Date()+seq(0, 180, by=30) ) )
[1] 2018.25 2018.25 2018.25 2018.50 2018.50 2018.50 2018.50