How to Apply the as.POSIXlt Function in R (Example Code)

In this tutorial, I’ll demonstrate how to manipulate date and time objects using the as.POSIXlt function in the R programming language.

Construction of Example Data

my_dates <- c("2021-10-13 09:12:39",    # Create vector of dates
              "2026-05-07 07:40:53",
              "2023-03-01 11:31:22")
my_dates
# [1] "2021-10-13 09:12:39" "2026-05-07 07:40:53" "2023-03-01 11:31:22"

Example: How to Apply the as.POSIXlt() Function

as.POSIXlt(my_dates)                    # Using as.POSIXlt
# [1] "2021-10-13 09:12:39 UTC" "2026-05-07 07:40:53 UTC"
# [3] "2023-03-01 11:31:22 UTC"

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