The date variable/column in a dataset is of utmost importance in terms of carrying out a Time series analysis and exploratory data analysis.
In R, most of the times a Date-format variable is read as a character type from any dataset. If you want to carry out any sort of analysis w.r.t dates then you must convert this character type variable to date.
In this Recipe, you will learn how to find weekday and week number from a date in R.
We will create a character variable in Date format (YYYY-MM-DD)
date_1 = "2020-05-01" date_1
We use strftime() to find both Weeknumber and Weekday. It is Date-time conversion function to and from Characters
Syntax: strftime(x, format = )
# to get the details of the function ?strftime # format = %A for getting corresponding weekday full name week_day = strftime(date_1, format = "%A") week_day
# format = %V for getting corresponding weeknumber between 1-53 week_num = strftime(date_1, format = "%V") week_num