[R] Missing data?

Gabor Grothendieck ggrothendieck at gmail.com
Mon Nov 28 02:35:55 CET 2011


On Sun, Nov 27, 2011 at 8:10 PM, Kevin Burton <rkevinburton at charter.net> wrote:
> This has been very helpful. Thank you.
>
> At the risk of further confirming my ignorance and taxing your patience I
> would like to add another question. How would I modify this code so that
> each week starts with the same day of the week regardless of the year? I
> would add this stipulation so that for multiple years I always get the same
> 'week-number' like
>
>> format(as.Date("2011-11-27"), "%W-%w")
> [1] "47-0"
>
> The convention (at least for US culture) seems to be that the week starts
> with Sunday (it is index 0 for day of week). So it would be convenient if
> the code was modified so that each 'week' began on Sunday. The partial at
> the beginning would just start with the day of week that was at the start. I
> still would want to aggregate that 'week-number's that are greater than 51
> like you have shown.

It would be the same except replace the calculation of yr.wk with:

tt <- time(z)
yr.wk <- as.numeric(format(tt, "%Y")) + pmin(as.numeric(format(tt,
"%W")), 51)/52

This puts the 1st Sunday of the year and the days prior to it in week
0, the next 7 days are in week 1 and so on.  All days after the 51st
Sunday are either in week 51 or are forced to be.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list