Re: [R] question about date's

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Tue 13 Dec 2005 - 01:44:59 EST

On Mon, 12 Dec 2005, Peter Dalgaard wrote:

> Prof Brian Ripley <ripley@stats.ox.ac.uk> writes:
>
>> On Mon, 12 Dec 2005, ronggui wrote:
>>
>>>> x<-as.Date(c("2005-07-01", "2005-07-02","2005-07-03","2005-07-04","2005-07-05"))
>>>> weekdays(x)
>>> [1] "星期五" "星期六" "星期日" "星期一" "星期二"
>>>
>>>> months(x)
>>> [1] "七月" "七月" "七月" "七月" "七月"
>>
>>
>> He asked for week numbers. That's nothing like as easy, as it is not
>> well-defined. But
>>
>>> strftime(as.POSIXlt(x), "%U")
>> [1] "26" "26" "27" "27" "27"
>>
>> is one possibility ("%W" is another). This approach will do the other
>> requests just as easily.
>
> %W seems to be what is known as "ISO dates" (week starts on Monday),
> except that
>
>> strftime(as.POSIXlt(as.Date("2005-01-01")), "%U")
> [1] "00"
>
> should be week 53, 2004 according to my printed calendar, and emacs
> calendar-mode too.

I _did_ say

>> That's nothing like as easy, as it is not well-defined.

The POSIX definition is

%U

     Replaced by the week number of the year as a decimal number [00,53].
     The first Sunday of January is the first day of week 1; days in the
     new year before this are in week 0.

%W
     Replaced by the week number of the year as a decimal number [00,53].
     The first Monday of January is the first day of week 1; days in the
     new year before this are in week 0.

so it is doing what it is documented to do. I'd take POSIX as more definitive than Emacs ....

-- 
Brian D. Ripley,                  ripley@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

______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Received on Tue Dec 13 02:08:33 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:41:35 EST