[R] Assigning Week Numbers

Gustaf Rydevik gustaf.rydevik at gmail.com
Wed Apr 21 17:48:45 CEST 2010

On Tue, Apr 20, 2010 at 7:59 PM, Michael Hosack <mhosack9 at hotmail.com> wrote:
> R experts,
> How could I extract the week number from a date vector (in Date class)
> such that week numbering (week 1...2...) begins (May 01) and ends
> (October 31) on the same specific dates each year? Week numbering
> must conform to the following day numbering format (Sat=1,Sun=2,Mon=3.....Fri=7).
> This means that new weeks must begin on Saturdays, and end on Fridays
> (except for the first date of May 01, which always begins week 1; week 2
> begins on the proceeding Saturday). This needs to be applicable across years
> to work effectively. I have tried using both vectorized and loop approaches with
> no success.
> I am including a bit of old Systat code that does the trick simply and concisely.
> If anyone knows an analogous method in R please let me know. My R dataframe contains
> all the variables and data in the Systat temp file.
> Use sched3.t
> Save sched4.t
> Hold
> By mm dd
> If bof then let week=1
> Else if bog and DOW$="SAT" then let week = week + 1
> Run
> Thank you,
> Mike

>From your code, it seems as if you're assuming that SCHEDULE3 contains
all consecutive saturdays, without skipping any. Is that correct?


More information about the R-help mailing list