[R] Assigning a sequence to a subsetted data frame variable

Hosack, Michael mhosack at state.pa.us
Mon Mar 15 18:45:09 CET 2010

Hey folks,

I have a difficult (at least for me) problem that I was hoping 
one of you may know how to solve. I want to assign a sequence 
to subsets of a variable in a data frame based on date. 
The variable is 'SITE1' and the date is a unique day (DD) and 
month (MM) combination. The sequence contains site numbers 101:104, 
and each day-month combination takes four site numbers from that 
sequence in an order dependent upon which site number is listed. 
For example, I need a sequence of 101,102,103,104 if 101 is the 
number listed, 102,103,104,101 if 102 is the number listed, 104,101,
102,103 if the 104 is the number listed for a given DD MM combination, 
etc. As a further example, for every sequence that happens to be 102,102,102,102 
for a MM DD combination I want to replace it with 102,103,104,101. 
Please see the attached partial dataframe. Any help would be 
greatly appreciated. I have tried creating a function using seq() 
and then using ddply, and also writing a loop with no luck. 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Dataframe.pdf
Type: application/pdf
Size: 76576 bytes
Desc: Dataframe.pdf
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100315/a0c7cdf1/attachment.pdf>

More information about the R-help mailing list