convert character or numerical to time of date

Hey everyone, new to R here and I'm having a bit of trouble. I have a column of data from a csv file, opened on R. It contains different time stamps, for example:
060102
050144
040107
000008
....
And I'm trying to convert it into time so that when exported into an Excel file it would look like:
06:01:02
05:01:44
04:01:07
00:00:08

So far I've had two problems: I can use the hms function (as.hms) but it only works on numericals. If I convert my data into num, then for example the last time stamp just becomes '8' cause leading zeroes dissappear. The hms function then works but I don't understand why, the times become completely wrong, for example 06:01:02 will become 16:41:42. Otherwise, I've tried strptime to apply on the data as 'characters', but then it just won't work...

Not sure if I've been very clear. Here is my script anyways:
vms <- read_delim("my-pathway",
delim = "/", escape_double = FALSE, col_names = FALSE,
trim_ws = TRUE)
date <- vms[[24]]
heure <- vms[[27]]
latitude <- vms[[12]]
longitude <- vms[[15]]
vitesse <- vms[[18]]

heure <- as.numeric(heure)

df <- data.frame(Date = c(date),
Heure = c(heure),
Latitude = c(latitude),
Longitude = c(longitude),
Vitesse = c(vitesse))

df$Date <- ymd(df$Date)

df$Heure<-as_hms(df$Heure)

write_xlsx(df, "~/'mypathway")

Sorry its in French. Date is date, heure is hours, and it's on hours that I'm having trouble.

Thanks in advance if anyone can help !!

Happy to help if you can create some sort of proper reprex (FAQ: How to do a minimal reproducible example ( reprex ) for beginners) for this. Lots of people also turn to lubridate to deal with dates specifically https://lubridate.tidyverse.org/ .

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.