[R] Week number from a date

Jan van der Laan rhelp at eoos.dds.nl
Wed Feb 22 16:49:10 CET 2012


The suggestion below gives you week numbers with week 1 being the week  
containing the first monday of the year and weeks going from monday to  
sunday. There are other conventions. The ISO convention is that week 1  
is the first week containing at least 4 days in the new year (week 1  
of 2012 starts on 2nd januari; week 1 of 2008 starts on december 29th  
2008).

http://www.r-bloggers.com/iso-week/

gives a function for that type of week numbers (not tested by me).

Jan



Patrick Breheny <patrick.breheny at uky.edu> schreef:

> To give a little more detail, you can convert your character strings  
> into POSIX objects, then extract from it virtually anything you  
> would want using strftime.  In particular, %W is how you get the  
> week number:
>
>> dateRange <- c("2008-10-01","2008-12-01")
>> x <- as.POSIXlt(dateRange)
>> strftime(x,format="%W")
> [1] "39" "48"
>
> --Patrick
>
> On 02/22/2012 08:37 AM, Ingmar Visser wrote:
>> ?strptime is a good place to start
>> hth, Ingmar
>>
>> On Wed, Feb 22, 2012 at 2:09 PM, arunkumar1111<akpbond007 at gmail.com>  wrote:
>>
>>> Hi
>>>
>>> My data looks like this
>>>
>>> startDate="2008-06-01"
>>>
>>> dateRange =c( "2008-10-01","2008-12-01")
>>> Is there any method to find the week number from the startDate range
>
> ______________________________________________
> 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