Convert Hours, Minutes & Seconds (hms) to Seconds in R (Example Code)
In this R tutorial you’ll learn how to convert hours, minutes, and seconds into seconds only.
Creation of Example Data
x <- c("01:11:17") # Create example hours, minutes & seconds x # [1] "01:11:17" |
x <- c("01:11:17") # Create example hours, minutes & seconds x # [1] "01:11:17"
Example: Convert Hours, Minutes & Seconds to Seconds Using period_to_seconds() Function of lubridate Package
install.packages("lubridate") # Install & load lubridate package library("lubridate") |
install.packages("lubridate") # Install & load lubridate package library("lubridate")
period_to_seconds(lubridate::hms(x)) # Convert hms to seconds # [1] 4277 |
period_to_seconds(lubridate::hms(x)) # Convert hms to seconds # [1] 4277
Related Tutorials
In the following, you can find some further resources that are similar to the topic of this article.