Given a vector of dates (could span multiple years):
exampleDates = as.Date( 1 : 15, origin = as.Date( "2012-12-25" ) )
I’d like to generate an identifier that groups dates into weeks. So assuming a calendar that starts on Sunday:
- the 26th to the 29th would produce the same identifier
- the 30th through the 5th have the same id
- the 6th through the 9th have the same id
Here’s a flawed attempt:
strftime( exampleDates , format = "%Y%W" )
It sees the 31th and the 1st as different weeks (no surprise). I’m looking for something similar to strftime that will generate an identifier (character, numeric, whatever) that I can use to group the dates by week.
I’m sure there’s some clever function out there already.
This will assign a unique integer to groups of dates that fall within a given week: