0

How would I convert seconds into h/m/s format. I've tried to use seconds_to_period but it only gives the value in seconds. e.g

ID   Time
1    345 secs
2    121 secs
3     78 secs

I want this is in HH:MM:SS format how is this done?

b10
  • 1
  • 3
  • See https://stackoverflow.com/a/70843341/3358272; while that _question_ asks about the opposite direction, my answer provided functions for both directions. – r2evans Jul 27 '22 at 15:45

1 Answers1

0

We may use hms from hms after converting to period

library(lubridate)
df1$Time <- hms::hms(seconds_to_period(readr::parse_number(df1$Time)))

-output

> df1
  ID     Time
1  1 00:05:45
2  2 00:02:01
3  3 00:01:18

data

df1 <- structure(list(ID = 1:3, Time = c("345 secs", "121 secs", "78 secs"
)), class = "data.frame", row.names = c(NA, -3L))
akrun
  • 874,273
  • 37
  • 540
  • 662