Re: [R] How to get week of the year, scale 1-52?

From: Eik Vettorazzi <E.Vettorazzi_at_uke.uni-hamburg.de>
Date: Tue, 18 Mar 2008 14:51:14 +0100

But usually weeks start with a Monday. So what should happen when new year isn't on a Monday? format(days, "%W") puts the first Monday of the year in the first week, which makes sense.

hth.

Lauri Nikkinen schrieb:
> Yeah, that's correct. I can accept that there is more than 52 weeks in
> a year (:-)) but it's hard to accept that the first week e.g in this
> example is 00 (year 2008). Should the first week be the first one, 1?
>
> -Lauri
>
> 2008/3/18, John Kane <jrkrideau_at_yahoo.ca>:
>
>> 365/7 != 52. You have more than 52 weeks in each
>> year.
>>
>>
>> --- Lauri Nikkinen <lauri.nikkinen_at_iki.fi> wrote:
>>
>>
>>> R users,
>>>
>>> I have a vector of dates
>>>
>>> days <- seq(as.Date("2007/1/1"),
>>> as.Date("2008/1/31"), "days")
>>>
>>> and I would like to have week numbers from 1 to 52
>>> for each year. How
>>> do I do that? Now I get 00-53 using
>>>
>>> format(days, "%W")
>>>
>>>
>>>> range(format(days, "%W"))
>>>>
>>> [1] "00" "53"
>>>
>>> I have read "Date and Time Classes in R" (R news
>>> 01/04 by Gabor
>>> Grothendieck and Thomas Petzoldt) with no help.
>>>
>>> Thanks
>>> Lauri
>>>
>>> ______________________________________________
>>> 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.
>>>
>>>
>>
>> Be smarter than spam. See how smart SpamGuard is at giving junk email the boot with the All-new Yahoo! Mail. Click on Options in Mail and switch to New Mail today or register for free at http://mail.yahoo.ca
>>
>>
>
> ______________________________________________
> 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.
>

-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/42803-8243
F ++49/40/42803-7790

______________________________________________
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.
Received on Tue 18 Mar 2008 - 14:15:06 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 22 Mar 2008 - 15:30:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive