I'll tell you something. It would be better for me to munge the data before I run the code with conditions. I'm still working on conversion times. My codes are used the way I like
c("2h 50m", "7h 25m", "19h", "5h 25m", "4h 45m", "2h 25m", "15h 30m",
"21h 5m", "25h 30m", "7h 50m", "13h 15m", "2h 35m", "2h 15m",
"12h 10m", "2h 35m", "26h 35m", "4h 30m", "22h 35m", "23h", "20h 35m",
"5h 10m", "15h 20m", "2h 50m", "2h 55m", "13h 20m", "15h 10m",
"5h 45m", "5h 55m", "2h 50m", "2h 15m", "2h 15m", "13h 25m",
"2h 50m", "22h", "5h 30m", "10h 25m", "5h 15m", "2h 30m", "6h 15m",
"11h 55m", "11h 5m", "8h 30m", "22h 5m", "2h 45m", "12h", "2h 50m",
"2h 50m", "2h 15m", "16h 5m", "19h 55m")
The output should look like this: 02:50:00
This is my code:
data$Duration <- str_replace_all(data$Duration, "[^\\d]", ":")
data$Duration <- str_replace_all(data$Duration, "::", ":")
data$Duration <- paste(data$Duration, "00:00")
data$Duration <- str_replace_all(data$Duration, " ", "")
data$Duration <- format(as.POSIXct(data$Duration, format = "%H:%M:%S"), "%H:%M:%S")
c("02:50:00", "07:25:00", "19:00:00", "05:25:00", "04:45:00",
"02:25:00", "15:30:00", "21:05:00", NA, "07:50:00", "13:15:00",
"02:35:00", "02:15:00", "12:10:00", "02:35:00", NA, "04:30:00",
"22:35:00", "23:00:00", "20:35:00", "05:10:00", "15:20:00", "02:50:00",
"02:55:00", "13:20:00", "15:10:00", "05:45:00", "05:55:00", "02:50:00",
"02:15:00", "02:15:00", "13:25:00", "02:50:00", "22:00:00", "05:30:00",
"10:25:00", "05:15:00", "02:30:00", "06:15:00", "11:55:00", "11:05:00",
"08:30:00", "22:05:00", "02:45:00", "12:00:00", "02:50:00", "02:50:00",
"02:15:00", "16:05:00", "19:55:00")
The output is as I would like it, but there are NAs even though I don't see any errors with my codes.