Creating a Unique Sequence of Dates
Solution 1:
As I noted in my comment, seq
has method for dates, seq.Date
:
seq(as.Date('2011-01-01'),as.Date('2011-01-31'),by = 1)
[1] "2011-01-01" "2011-01-02" "2011-01-03" "2011-01-04" "2011-01-05" "2011-01-06" "2011-01-07" "2011-01-08"
[9] "2011-01-09" "2011-01-10" "2011-01-11" "2011-01-12" "2011-01-13" "2011-01-14" "2011-01-15" "2011-01-16"
[17] "2011-01-17" "2011-01-18" "2011-01-19" "2011-01-20" "2011-01-21" "2011-01-22" "2011-01-23" "2011-01-24"
[25] "2011-01-25" "2011-01-26" "2011-01-27" "2011-01-28" "2011-01-29" "2011-01-30" "2011-01-31"
Solution 2:
I have made the same mistake with seq() attempting to make a numeric sequence. Don't use the ":" operator between arguments, and they will need to be dates if you want to make a date sequence. Another way is to take one date and add a numeric sequence starting with 0:
> as.Date("2000-01-01") + 0:10
[1] "2000-01-01" "2000-01-02" "2000-01-03" "2000-01-04" "2000-01-05" "2000-01-06"
[7] "2000-01-07" "2000-01-08" "2000-01-09" "2000-01-10" "2000-01-11"
Solution 3:
You could try timeBasedSeq
in the xts package. Notice the argument is a string and the use of the double-colon.
timeBasedSeq("2011-08-01::2011-08-31")