JRHami
November 13, 2019, 3:08pm
1
I have a character string that I know to be of the format HHMMSS (no separators) how do I convert to an unambiguous format such as HH:MM:SS
x <- "005257"
parse_date_time gets me close but I don't want the arbitrary date and timezone.
parse_date_time("005257","HMS")
[1] "0000-01-01 00:52:57 UTC"
would like
"00:52:57"
FJCC
November 13, 2019, 3:34pm
2
What kind of object to you want to get out of this process? If you want a string then
gsub("(..)(..)(..)", "\\1:\\2:\\3", "005257")
#> [1] "00:52:57"
Created on 2019-11-13 by the reprex package (v0.3.0.9000)
1 Like
pete
November 13, 2019, 3:39pm
3
To add on to FJCC's response. You can use the hms
package to work with time-of-day variables: https://hms.tidyverse.org/
2 Likes
Another option
library(readr)
x <- "005257"
parse_time(x, "%H%M%S")
#> 00:52:57
2 Likes
system
Closed
December 4, 2019, 8:44pm
5
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.