How to create a range of dates in R
Does this help?
seq(as.Date("2014/09/04"), by = "day", length.out = 5)# [1] "2014-09-04" "2014-09-05" "2014-09-06" "2014-09-07" "2014-09-08"
edit: adding in something about timezones
this works for my current timezone
seq(c(ISOdate(2014,4,9)), by = "DSTday", length.out = 5) #[1] "2014-04-09 08:00:00 EDT" "2014-04-10 08:00:00 EDT" "2014-04-11 08:00:00 EDT" "2014-04-12 08:00:00 EDT"#[5] "2014-04-13 08:00:00 EDT"
edit2:
OlsonNames() # I used this to find out what to write for the JST tz - it's "Japan"x <- as.POSIXct("2014-09-04 23:59:59", tz="Japan")format(seq(x, by="day", length.out=5), "%Y-%m-%d %Z")# [1] "2014-09-04 JST" "2014-09-05 JST" "2014-09-06 JST" "2014-09-07 JST" "2014-09-08 JST"
Here's an answer, admittedly worse than @jalapic's, that doesn't use seq and instead uses a for loop:
date1 <- "2014-09-04"date2 <- "2014-09-11"dif <- as.numeric(abs(as.Date(date1) - as.Date(date2)))dates <- vector()for (i in 1:dif) { date <- (as.Date(date1) + i) dates <- append(dates, date)}# [1] "2014-09-05" "2014-09-06" "2014-09-07" "2014-09-08" "2014-09-09" "2014-09-10" "2014-09-11