Is this what you mean?
library(dplyr)
library(readxl)
library(hms)
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")
driver_data %>%
mutate(across(contains("time"), as_hms),
across(contains("date"), as.Date),
p2_request = as.POSIXct(paste(p2_request_date, p2_request_time)),
p3_begin = as.POSIXct(paste(p3_begin_date, p3_begin_time)),
p3_end = as.POSIXct(paste(p3_end_date, p3_end_time))) %>%
select(p2_request, p3_begin, p3_end, trip, gross_orig_driver_pay) %>%
mutate(time_passed = difftime(p2_request, lead(p3_end), units = "hour"))
#> # A tibble: 90 x 6
#> p2_request p3_begin p3_end trip
#> <dttm> <dttm> <dttm> <chr>
#> 1 2021-03-03 12:10:33 2021-03-03 12:15:39 2021-03-03 12:33:17 completed
#> 2 2021-03-03 11:29:21 2021-03-03 11:34:16 2021-03-03 12:06:27 completed
#> 3 2021-03-03 10:44:26 2021-03-03 10:47:41 2021-03-03 11:17:06 completed
#> 4 2021-03-03 10:08:28 2021-03-03 10:11:47 2021-03-03 10:42:37 completed
#> 5 2021-03-03 09:42:02 2021-03-03 09:56:46 2021-03-03 10:02:06 completed
#> 6 2021-03-03 09:32:20 2021-03-03 09:38:45 2021-03-03 09:46:05 completed
#> 7 2021-03-03 08:45:00 2021-03-03 08:43:39 2021-03-03 09:30:22 completed
#> 8 2021-03-03 07:30:00 2021-03-03 07:27:44 2021-03-03 08:24:32 completed
#> 9 2021-03-03 06:22:22 2021-03-03 06:32:16 2021-03-03 07:11:43 completed
#> 10 2021-03-02 15:11:13 2021-03-02 15:16:55 2021-03-02 15:43:38 completed
#> # … with 80 more rows, and 2 more variables: gross_orig_driver_pay <dbl>,
#> # time_passed <drtn>
Created on 2021-04-26 by the reprex package (v2.0.0)
If this doesn't solve your problem, please provide a proper REPRoducible EXample (reprex) illustrating your issue.