[R] How to assign week numbers to a time-series (duplicate message in plain text formatting)
mhosack at state.pa.us
Wed Mar 10 20:09:50 CET 2010
I want to thank everyone who has provided me advice on how to solve this problem, it was all very helpful. However, I am still left with one issue remaining. All of the methods provided still require me to input the origin date, which to lead to correct week number assignment, must be the last Saturday prior to the survey start date of May 01 or May 01 if that date happens to be a Saturday. I would prefer a method that is robust to whether or not May 01 is a Saturday and does not require me to input any data other than the initial dataframes. This program will be used to produce sampling schedules for many subsequent years, most of which will not begin on a Saturday. Does anyone know how this could be done? Please see the attached partial copy of my dataframe. The survey runs from May 01 to Oct 31.
Thanks so much,
From: Hosack, Michael
Sent: Friday, March 05, 2010 4:24 PM
To: 'R-help at r-project.org'
Subject: How to assign week numbers to a time-series
My progress has stalled on finding a way of creating a somewhat complicated variable to add to my existing dataframe and I am hoping one of you could help me out. The dataframe below contains only a fraction of the data of my complete dataframe, but all of the variables. What I want to do is add another variable named 'WEEK' to this dataframe that is assigned 1 for row 1 and remains 1 until the first SAT (i.e. Saturday) under variable 'DOW' (day of week) occurs, at which point variable 'WEEK' is now assigned 2. 'WEEK' should continue to be assigned 2 until the following SAT under variable 'DOW' at which variable 'WEEK' will now be assigned 3, and so on. In this scheme, weekdays are such that SAT=1, SUN=2, MON=3,.....FRI=7. I am basically trying to assign week numbers to potential sampling days in a survey season for use in a program that will generate a fisheries creel survey schedule. I should note that if element 1 happens to have DOW=SAT (that is the case this year, since the first day of our survey 05/01 is a Saturday), then WEEK 1 begins on day 1 (05/01/2010) and WEEK 2 will begin on the first SAT under variable DOW. I hope I explained this clearly enough, if not let me know. If this sent twice, I apologize.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 86921 bytes
More information about the R-help