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"

Example: Convert Hours, Minutes & Seconds to Seconds Using period_to_seconds() Function of lubridate Package

install.packages("lubridate")           # Install & load lubridate package
library("lubridate")
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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top