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

Hadley Wickham hadley at rice.edu
Wed Mar 9 22:21:32 CET 2011


On Wed, Mar 9, 2011 at 3:04 PM, Dimitri Liakhovitski
<dimitri.liakhovitski at gmail.com> wrote:
> Hello!
>
> I have a date (a Monday):
>
> date<-20081229
> mydates<-as.Date(as.character(date),"%Y%m%d")
>
> What package would allow me to create a vector that starts with that
> date (mydates) and contains dates for 51 Mondays that follow it (so,
> basically, 51 dates separated by a week)?

library(lubridate)
mydates <- ymd(date) + weeks(0:51)

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-help mailing list