I realize this may be a very basic question, but I am under a time crunch and cannot for the life of me figure this out. Someone altered this data I need to use to go from HH:MM:SS to %%H %%M %%S without leading 0s when these values are not double digits (so maybe more like (%)%H (%)%M (%)%S if that makes sense). For example, 10:32:20 would be represented as 10H 32M 20S. I can deal with this just fine. However, if it is 7:30:04, for example, it will be 7H 30M 4S. I don't understand why someone would use this format - is this a standard in some package?
I am looking for a way to convert this to to the HH:MM:SS format / parse it into a time object.
I initially only realized that the seconds were missing leading 0s, so that was what this formula was for..
# turn e.g. 10H 12M 30S -> 10:12:30
df$Time = gsub(" ", "", c(df$Time))
df$Time = gsub("[^0-9]", ":", c(df$Time))
df$Time = gsub("::", ":", c(df$Time))
df$Time = substring(df$Time,1,nchar(df$Time) - 1)
for (i in seq_along(df$Time)) {
if (nchar(df$Time[i]) == 7) {
gsub("([0-9]*$)", paste(0, str_sub(df$Time[i], start=7), sep=""), df$Time[i])
}
}