[R] Week of the Year date conversion

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Dec 15 12:22:47 CET 2003


On Mon, 15 Dec 2003, Wayne Jones wrote:

> 
> Hello there fellow R-users, 
> 
> I have received some data which comes in the following format: 
> 
> example1<-"200301"
> 
> The first 4 digits correspond to the year and the remaining 2 digits
> correspond to the week of the year. 
> I have tried to convert this to a date by using strptime as follows:
> 
> strptime(example1,format="%Y%U")
> 
> where U (looking up strptime) is the week of the year but it always returns
> NA. 

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.

Brian

-- 
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