[R] getting ISO week

Gabor Grothendieck ggrothendieck at gmail.com
Thu Dec 11 20:40:14 CET 2008


According to the definition in ?strptime (which is not the same as the
ISO definition):

format(x, "%W") returns

"Week of the year as decimal number (00–53) using Monday as the first
day of week (and typically with the first Monday of the year as day 1
of week 1). The UK convention."

The first day of 2008 is a Tuesday which means that 2008 starts in week 0.

On Thu, Dec 11, 2008 at 2:31 PM, Hans W. Borchers <hwborchers at gmail.com> wrote:
> Gabor Grothendieck <ggrothendieck <at> gmail.com> writes:
>
>>
>> format(d, "%U") and format(d, "%W") give week numbers using
>> different conventions.  See ?strptime
>
> Gabor,
>
> the results of format(aDate, "W") appear to be incorrect anyway, see:
>
>    format(as.Date("2008-01-01"), "%W")     #-> "00"
>
> There is never a week 0, this should be week 1.
>
>    format(Sys.Date(), "%W")                #-> "49"
>
> but my business calendar says today's (Dec. 11, 2008) week is week 50
> which is what Brian Ripleys proposed 'strftime(x, "%V")' returns.
>
> There could be a format "%E" (not used up to now) for returning a
> correct week number according to the European standard.
>
> Yours,  Hans Werner
>
>> On Thu, Dec 11, 2008 at 7:43 AM, Gustaf Rydevik
>> <gustaf.rydevik <at> gmail.com> wrote:
>> > Hi all,
>> >
>> > Is there a simple function already implemented for getting the ISO
>> > weeks of a Date object?
>> > I couldn't find one, and so wrote my own function to do it, but would
>> > appreciate a pointer to the "default" way. If a function is not yet
>> > implemented, could the code below be of interest to submit to CRAN?
>> >
>> > Best Regards,
>> >
>> > Gustaf
>> >
>> > --------------------
>>
>> ... [rest deleted]
>> ______________________________________________
>> R-help <at> r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list