[R] Week of the Year date conversion
Berwin Turlach
berwin at maths.uwa.edu.au
Mon Dec 15 13:02:27 CET 2003
>>>>> "BR" == Barry Rowlingson <B.Rowlingson at lancaster.ac.uk> writes:
BR> Ah ha. Use '%w' for 'day of week':
>> strptime("2003 05 06", format="%Y %U %w")
BR> [1] "2003-02-02"
BR> I dont have a calendar to hand to check that 2 Feb is the 6th
BR> day of the 5th week....
It's not, it is the first day of the 5th week in 2003. Moreover:
> strptime(paste("2003 05 0", 0:6, sep=""), format="%Y %U %w")
[1] "2003-02-02" "2003-02-02" "2003-02-02" "2003-02-02" "2003-02-02"
[6] "2003-02-02" "2003-02-02"
I guess this behaviour is consistent with the description of %U:
`%U' Week of the year as decimal number (00-53) using the first
Sunday as day 1 of week 1.
??
> strptime(paste("2003 01 0", 0:6, sep=""), format="%Y %U %w")
[1] "2003-01-05" "2003-01-05" "2003-01-05" "2003-01-05" "2003-01-05"
[6] "2003-01-05" "2003-01-05"
5 January 2003 was the first Sunday in 2003.
Cheers,
Berwin
More information about the R-help
mailing list