I have a variable that needs to be converted to military time. This variable is very messy because it lacks consistency in the format.
Here is an example of what might be found in the variable.
x <- c("0.9305555555555547", "15:20 Found", "10:00:00 AM Found", "0.125", "Found 1525")
So far I had some success in getting everything in a more consistent format with RegEx:
x <- str_extract(x, "[0-9]+.+[0-9]|[0-9][0-9][:][0-9][0-9]")
x <- str_remove(x, "[:]")
x <- str_remove(x, "[:][0-9][0-9]$")
As you can see I get: "0.9305555555555547", "1520", "1000", "0.125", "1525"
The problem is the decimals need to be multiplied by 2400 to get back to military time but I also don't want to multiply integers (since those are already in military time).
x is essentially a variable in a dataframe.
I was thinking about using if/else logic but I don't know how to implement that.
To clarify, I want:
Input: "0.9305555555555547", "15:20 Found", "10:00:00 AM Found", "0.125", "Found 15:25"
Output: "2233", "1520", "1000", "0300", "1525"