I am new into the R world. So, I have a data frame that have two date columns that comprises of date and time, but stored as a character, so I want to use the difftime() function to make a column that could store in seconds the time between the two date columns. I tried changing the data type of the date column(start_time) from character to a date-time format severally, using different date-time functions,, just so I could be able use the difftime() function on it, but to no avail . Please, help.
Below I uploaded an image of the table and pasted the codes I used together with the errors they've returned. where start_time and end_time are the date columns.
1
all_trips3 <- as.POSIXlt(all_trips3$start_time)
got this error after I ran it "Error in as.POSIXlt.character(all_trips3$start_time) : character string is not in a standard unambiguous format"
2
all_trips3$start_time <- (strptime(all_trips3$start_time, "%m/%d/%y")
It ran but made date column(start_time) into NA values
3
all_trips3$start_time <- as.POSIXct(all_trips3$start_time, "%m/%d/%y %H:%M:%S", tz = Sys.timezone())
ran too, but it made the date(start_time) column into NA values
4. saw this here on stackflow while looking for solutions
all_trips3 <- all_trips3 %>%
mutate(across(c(start_time, end_time), as.POSIXct,
format = "%m/%d/%y %H:%M"))
ran too, but had my date columns filled with NA values