How to generate a sequence of dates in r?

3

How do I generate a list with dates, for example, starting in 2011-07-01 and ending in 2011-10-31?

    
asked by anonymous 11.10.2017 / 18:55

1 answer

5

Using the seq function:

datas_dia    <- seq(from=as.Date("2011-07-01"), to=as.Date("2011-10-31"), by="day")

datas_semana <- seq(from=as.Date("2011-07-01"), to=as.Date("2011-10-31"), by="week")

datas_mes    <- seq(from=as.Date("2011-07-01"), to=as.Date("2011-10-31"), by="month")

where

  • as.Date converts string to date format

  • seq creates the sequence

  • from tells where the sequence begins

  • to tells where the sequence ends

  • by determines the sequence increment (in my example, increments are day, week, and month, respectively)

11.10.2017 / 19:12