Determine Max & Min Dates of Vector in R (Example Code)

This article illustrates how to return the earliest and latest date of a date vector in the R programming language.

Construction of Example Data

x <- c("2025-07-13", "2023-05-07", "2022-10-11",  # Example dates in R
       "2019-04-25", "2021-12-01", "2024-03-21",
       "2023-05-15", "2026-04-11", "2020-03-19")
x                                                 # Display dates in RStudio console
# [1] "2025-07-13" "2023-05-07" "2022-10-11" "2019-04-25" "2021-12-01" "2024-03-21" "2023-05-15" "2026-04-11" "2020-03-19"

Example: Find Latest & Earliest Date

max(as.Date(x))                                   # Maximum date
# [1] "2026-04-11"
min(as.Date(x))                                   # Minimum date
# [1] "2019-04-25"

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