How to Get the Day of a Date Object in R (Example Code)
In this tutorial you’ll learn how to return only the day of a Date object in R.
Creation of Example Data
my_date <- as.Date(c("2021-06-13", # Creating vector of Date objects "2025-09-05", "2016-12-11")) my_date # Showing date vector in RStudio console # "2021-06-13" "2025-09-05" "2016-12-11" |
my_date <- as.Date(c("2021-06-13", # Creating vector of Date objects "2025-09-05", "2016-12-11")) my_date # Showing date vector in RStudio console # "2021-06-13" "2025-09-05" "2016-12-11"
Example: Applying format Function to Extract Day from Date
format(my_date, format = "%d") # Using format function # "13" "05" "11" |
format(my_date, format = "%d") # Using format function # "13" "05" "11"