I am attempting to convert a long list of values in a column from Hours:Minutes:Seconds into just Seconds. The code I have below works fine as long as the values are in H:M:S format, but I have values in random rows that are just in the M:S format (so no hours). When I try to perform the below code on them, I obviously obtain an NA for each of those values. Is there a way that I can search for only the values in M:S format, and only the H:M:S format, and convert them separately? Do I need to add an hours value in each of the M:S values so I can convert all at once? My code below:
as.numeric(strptime(df$x, format="%H:%M:%S") - as.POSIXct(format(Sys.Date())), units="secs")
Example of data:
Time
12:22:05
42:44
Example of data after running above:
Time
44525
NA
Try
parse_date_time
while using thelubridate
package.