How to convert date into days in R?

r
kaggle
data_wrangling

#1

Hello,

I’ve a column in my dataset which contains date and time. I want to extract the date and convert it into days (monday, tuesday, etc.) and add another column to my train dataset with these days. Which R functions can I use for the same and how?

class(train$datetime)
[1] "factor"
typeof(train$datetime)
[1] “integer”

head(train$datetime)
[1] 2011-01-01 00:00:00 2011-01-01 01:00:00 2011-01-01 02:00:00 2011-01-01 03:00:00
[5] 2011-01-01 04:00:00 2011-01-01 05:00:00
10886 Levels: 2011-01-01 00:00:00 2011-01-01 01:00:00 … 2012-12-19 23:00:00


#2

@pravin, check out ?weekdays. But make sure that the object that you are passing to it is of the class Date.