Convert Date to Weekday in R (Example)
This article shows how to convert a date object to the corresponding day of the week in the R programming language.
Example Data
We create an example vector with the as.Date function:
my_dates <- as.Date(c("2023-02-15", "2018-05-01", "1974-01-10")) # Create vector of dates |
my_dates <- as.Date(c("2023-02-15", "2018-05-01", "1974-01-10")) # Create vector of dates
Convert Dates to Days of the Week in R
We can convert our example dates to the corresponding days of the week with the weekdays function:
weekdays(my_dates) # Convert dates to weekdays # "Wednesday" "Tuesday" "Thursday" |
weekdays(my_dates) # Convert dates to weekdays # "Wednesday" "Tuesday" "Thursday"