When working with dates, I sometimes have counts, say of tweets from a certain account, that don't occur every day. When analyzing these data, it would be helpful to have every date present in my analysis data set, even those dates for which the count is zero. For some time, I didn't know how to do this. I tried:
library(lubridate)
mdy("1/1/2015") -> foo
mdy("1/1/2016") -> bar
foo:bar
which outputted a collection of 366 (consecutive) integers.
I then tried:
mdy(foo:bar)
which outputted 366 NAs, with a message that no origin value was specified.
Now, to get 366 dates, you can use as_date
from lubridate
:
as_date(foo:bar)
to get the consecutive 366 dates.