I am trying to calculate how many reports are running at a certain time.
The data is like:
ReportID StartTime Duration
1 2018-11-02 13:00:00 240 seconds
2 2018-11-02 14:00:00 300 seconds
3 2018-11-02 14:01:15 300 seconds
4 2018-11-02 14:00:00 5000 seconds
The ideal output will be:
Time #ReportsRunning
2018-11-01 13:00:00 0
2018-11-02 13:00:00 1
2018-11-02 14:00:00 2
2018-11-02 15:00:00 1
Is there anyway to do something like this? I am thinking about adding column to every timestamp I want to check. But that will make the table extremely wide.
Data in reproducible form:
df1 <- data.frame(
ReportID = 1:4,
StartTime = as.POSIXct(c("2018-11-02 13:00:00", "2018-11-02 14:00:00",
"2018-11-02 14:01:15", "2018-11-02 14:00:00")),
Duration = as.difftime(c(240, 300, 300, 5000), units = "secs")
)
df2 <- data.frame(
Time = as.POSIXct(c("2018-11-01 13:00:00", "2018-11-02 13:00:00",
"2018-11-02 14:00:00", "2018-11-02 15:00:00"))
)