[R] Week number from a date

2012-02-22 Thread arunkumar1111
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

-
Thanks in Advance
Arun
--
View this message in context: 
http://r.789695.n4.nabble.com/Week-number-from-a-date-tp4410223p4410223.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Week number from a date

2012-02-22 Thread Ingmar Visser
?strptime is a good place to start
hth, Ingmar

On Wed, Feb 22, 2012 at 2:09 PM, arunkumar akpbond...@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

 -
 Thanks in Advance
Arun
 --
 View this message in context:
 http://r.789695.n4.nabble.com/Week-number-from-a-date-tp4410223p4410223.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@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.


[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Week number from a date

2012-02-22 Thread Patrick Breheny
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, arunkumarakpbond...@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@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.


Re: [R] Week number from a date

2012-02-22 Thread Jan van der Laan


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.breh...@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, arunkumarakpbond...@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@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@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.


Re: [R] Week number from a date

2012-02-22 Thread Gabor Grothendieck
On Wed, Feb 22, 2012 at 8:09 AM, arunkumar akpbond...@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

__
R-help@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.