How to convert dates into days of week in R?



I was going through a dataset, where I had date and time in a single variable in the following format:

2011-01-01 01:00:00

I want to convert this date into the corresponding day of the week.Could you suggest some function for the same?

Thanks in advance!


Hi there,

You can make use of the “Lubridate” package in R to parse the date and then calculate the day of the week.

For eg:
date<-ymd_hms(“2016-06-06 09:45:12”)


Here. 1 means Sunday…and so on.

Hope it helps.`


Ensure that your date field is in proper format. (POSIXt)

You can use the function weekdays from base R for this.

weekdays(as.POSIXct(“2016-06-06 10:00:12”), abbreviate = F)
[1] "Monday"
weekdays(as.POSIXct(“2016-06-06 10:00:12”), abbreviate = T)
[1] “Mon”


Thanks a lot!