[R] Week number calculation

Gabor Grothendieck
Tue, 20 Apr 2010 00:00:24 -0000

If dd is of Date class then this code finds the number of days since
May 1st of the same year and then does an integer divide by 7 plus 1
so that the if dd lies in May 1 - May 7 it returns 1 as the week
number, etc.

dd <- as.Date("2000-06-01") # sample input
as.numeric(dd - as.Date(sub("-.*", "-05-01", dd))) %/% 7 + 1


On Mon, Apr 19, 2010 at 4:31 PM, Hosack, Michael <mhosack at state.pa.us>
wrote:
> R community,
>
> How could I extract the week number from a date vector
> (in class Date) such that week numbering (week 1...2...)
> begins (May 01) and ends (October 31) on the same specific
> dates each year?
>
> Thank you,
>
> Mike
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>