I am trying to calculate my email durations. I have emails grouped by ID. In this example, I have already grouped my emails by group A. I wish to calculate my email read time duration for group A. The code I am currently using, calculates its last and first time in seconds.
data <-rawdata %>%
group_by(ID) %>%
summarize(diff = difftime(last(as.POSIXct(Endtime, format ="%m/%d/%Y %I:%M:%S %p")),
first(as.POSIXct(Starttime, format = "%m/%d/%Y %I:%M:%S %p" )), units = "secs"))
However, I do not think this is an accurate display of my email reads. Overall, I am wanting the time difference by each row for a more accurate reading. The desired output would be (below) because it reveals the time difference by each row, allowing me to further SUM the entire diff column in order to determine my email duration in seconds.
Starttime Endtime ID diff
12/18/2019 4:06:59PM 12/18/2019 4:07:05 PM A 6 secs
12/18/2019 4:07:26PM 12/18/2019 4:07:28 PM A 1 secs
12/17/2019 6:48:06PM 12/17/2019 6:48:07PM A 1 sec
12/17/2019 6:25:16PM 12/17/2019 6:25:22PM A 6 secs
Any help is appreciated. I will continue to research this!