1

I have been stuck on this situation. I need to find time difference between start time and end time. I have tried different methods, but most of the time its either R is not recognising the code or giving me negative times when it passes midnight.

I used this code:

df <-   difftime(com_21$start_time,com_21$end_time, units = "mins")
com_21$ride_length <- df

where com_21 is the name of my data frame.

Data frame:
data frame

Data type using class(): data type using class()

benson23
  • 16,369
  • 9
  • 19
  • 38
Saad Ehsan
  • 11
  • 1
  • Welcome to StackOverflow, Saad! Please, provide a reproducible example: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – PaulS Feb 19 '22 at 15:19
  • Looks like could be easier if you combined date and time, eg `com_21$start_dt = lubridate::ymd_hms(paste(com_21$start_date, com_21$start_time))`. Then the difference in time will be straighforward. – Jon Spring Feb 19 '22 at 16:15

0 Answers0