[R] Week number from a date
Gabor Grothendieck
ggrothendieck at gmail.com
Wed Feb 22 17:07:06 CET 2012
On Wed, Feb 22, 2012 at 8:09 AM, 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
>
Is the question how many weeks are from the startDate to each of the
dateRange dates? If so, then try this:
startDate <- as.Date("2008-06-01")
dateRange <- as.Date(c( "2008-10-01","2008-12-01"))
floor(as.numeric(dateRange - startDate) / 7)
or depending on what the week is supposed to be we might want ceiling
in place of floor or neither floor nor ceiling if we want fractional
weeks.
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-help
mailing list