I'm trying to find a way to auto populate the start/end week dates for any given year. E.g. 4/12/2015 - 4/18/2015, 4/19/2015 - 4/25/2015, 4/26/2015 - 5/2/2015. I guess I could calculate those explicitly, but it's not very elegant. Thanks in advance!
AutoFill Weekday NamesSelect the cell, and point to the Fill Handle, at the bottom right corner of the selected cell. Press the left mouse button, and drag (up, down, left or right) -- the weekday names will appear in a pop-up tip, near the pointer.
Find first day and last days of the first week of year: read the %W
, %w
, %V
specifications under ?strptime
for more detail. Be aware that strptime
conventions are very finicky (e.g. you need exactly the right number of digits), possibly operating-system-dependent, and possibly locale-dependent ...
firstday <- as.Date(strptime("2010-01-0",format="%Y-%W-%w")) ## Sunday
lastday <- as.Date(strptime("2010-01-6",format="%Y-%W-%w")) ## Saturday
Now set up date sequences starting from those days:
seq.Date(firstday,as.Date("2010-12-31"),by="1 week")
seq.Date(lastday,as.Date("2010-12-31"),by="1 week")
You can use e.g. paste0(year,"-01-0")
if you want to do this more generally (without hard-coding the year).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With