[R] Week of the Year date conversion

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Dec 15 13:05:14 CET 2003


On Mon, 15 Dec 2003, Barry Rowlingson wrote:

> Prof Brian Ripley wrote:
> 
> > That is not a complete date!   Which day of the week is it?
> > 
> > 
> >>example1<-"200301"
> >>strptime(paste(example1, "1", format="%Y%U %d")
> > 
> > 
> > will work, and you need to do something like that to resolve the 
> > ambiguity.
> > 
> 
>   Doesn't seem to work:
> 
>   - 6th day of 5th week:
> 
>  > strptime("2003 05 06", format="%Y %U %d")
> [1] "2003-01-06"
> 
>   Ah ha. Use '%w' for 'day of week':

Or %u.  And %U %V %W all mean week of the year in different definitions.
Hence `something like that' (and I meant %u not %d).


>  > strptime("2003 05 06", format="%Y %U %w")
> [1] "2003-02-02"
> 
>   I dont have a calendar to hand to check that 2 Feb is the 6th day of 
> the 5th week....

It is on one definition.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list