[R] Vector of weekly dates starting with a given date

Gabor Grothendieck ggrothendieck at gmail.com
Wed Mar 9 23:17:46 CET 2011


On Wed, Mar 9, 2011 at 4:13 PM, Dimitri Liakhovitski
<dimitri.liakhovitski at gmail.com> wrote:
> I realize I can do something like this:
> date<-20081229
> mydates<-as.Date(as.character(date),"%Y%m%d")
> for(i in 1:52){  #
>  mydates<-c(mydates,mydates[length(mydates)]+7)
> }
>
> I just thought maybe there is a more elegant way...
> Thank you!

Here are two approaches:

as.Date("2008-12-29") + seq(0, length = 53, by = 7)

seq(as.Date("2008-12-29"), length = 53, by = "week")

-- 
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