How do I generate a list with dates, for example, starting in 2011-07-01 and ending in 2011-10-31?
How do I generate a list with dates, for example, starting in 2011-07-01 and ending in 2011-10-31?
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)