-1

I have a date in R and it's formatted as follows:

2018-08-31 01:00:00

Is there any way in R to add another column with the day of the week associated with the date? My dataset is very large.

  • 2
    `weekdays(as.Date("2018-08-31 01:00:00"))`? – jay.sf Oct 28 '19 at 11:48
  • This is a duplicate question, an earlier answer can be found [Find the day of a week](https://stackoverflow.com/a/9216316/1444043). – slackline Oct 28 '19 at 11:50
  • The problem is that in the column of the date I have the date (2018-08-31) and the hour, minute and second (01:00:00) as you can see above. The format of my date is different from the question you mentioned. – Thais Rangel Oct 28 '19 at 12:00

1 Answers1

0

This will probably do the trick for you. Experiment with different settings of the label- and abbr-arguments to get the derised results.

library(lubridate)
lubridate::wday( as.POSIXct( "2018-08-31 01:00:00", 
                             format = "%Y-%m-%d %H:%M:%S "), 
                 label = TRUE, 
                 abbr = FALSE )
Wimpel
  • 26,031
  • 1
  • 20
  • 37