From this data, I'm trying to calculate the time that has passed between p3_end_time and the following p2_request_time . For example, in row 3 of the excel sheet from Github link below, I'd like to know how much time lapsed from p3_end_time (11:23:25 AM and in row 1) and the following p2_request_time (11:29:44 AM in row 2). In some cases, p3_end_time will occur before the following p2_request_time and therefore will not need to be calculated.
It is not actually clear what you want as I cannot find the times you mention but this might work. I converted your spreadsheet into a .csv file for ease of dealing with times and date
Hi! Thank you. I'm new here and trying to figure out the ropes, but want to be helpful in both my asks and maybe helping others one day. This look right?
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(readxl)
library(hms)
library(readxl)
link <- "https://github.com/derek-l-thomas/time.data/raw/main/derek_sample.xlsx"
download.file(link, "driver_data.xlsx")
driver_data <- readxl::read_excel("driver_data.xlsx")
This is super helpful - thank you. I noticed how you were able to combine time and date, which seems to make this much easier.
(Excuse me for still learning how to paste the table in here, and for not clearly explaining the problem.)
Using row 2 of what you posted, the time_passed that you calculated should be 4 minutes and 6 seconds. That would be the time that's passed between the end of a driver's trip (p3_end, in row 2) and her next sequential request (p2_request, in row 1). Does that make sense?
Forgive me. I'm still struggling with pasting a data table using Tribble. I'm sure it's not as complicated as I'm making it. My example wasn't clear, but this is really helpful!
Using dat3 from your code above, and in row 2, do you know what unit 246 represents?
It should be 4 minutes and 6 seconds. That would be the time that's passed between the end of a driver's trip ("end", in row 2, 2021-03-03 12:06:27) and her next sequential request ("request", in row 1, 2021-03-03 12:10:33). Of course this means row 1 "dur" should be NA, since there's no data recorded after this trip.
That is exactly the result I get with my code but the units are "hours", for presentation purposes I can change the format so it becomes more evident to you.
The only issue that remains is that, in many cases, p3_end_time occurred before the subsequent p2_request_time. Eg, the request time in row 89 (2021-02-13 06:36:43) occurred before the p3_end_time in row 90. (2021-02-13 06:45:36) and therefore would be NA.