Extracting Week Number of Dates Vector in R (Example Code)

In this R tutorial you’ll learn how to convert dates to week numbers.

Creating Example Data

x <- c("2018-01-01", "2025-05-13", "2021-10-08")  # Vector of dates
x                                                 # Print dates to RStudio console
# [1] "2018-01-01" "2025-05-13" "2021-10-08"

Example: Extracting Week Number of Date in R

strftime(x,                                       # Returning week number
         format = "%V")
# [1] "01" "20" "40"

Further Resources

You may find some related R programming language tutorials on topics such as numeric values, data objects, and dates in the following list:

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