I want to calculate a count of items over time using their Start and End dates.
Some sample data
START <- as.Date(c(\"2014-01-01\", \"2014-01-02\
Using dplyr and foreach:
library(dplyr)
library(foreach)
df <- data.frame(START = as.Date(c("2014-01-01",
"2014-01-02",
"2014-01-03",
"2014-01-03")),
END = as.Date(c("2014-01-04",
"2014-01-03",
"2014-01-03",
"2014-01-04")))
df
r <- foreach(DATETIME = seq(min(df$START), max(df$END), by = 1),
.combine = rbind) %do% {
df %>%
filter(DATETIME >= START & DATETIME <= END) %>%
summarise(DATETIME, COUNT = n())
}
r