Im trying to convert a Date column in a csv file to a new column Day
using R. Day in terms of Monday Tuesday etc. Apparently yday gives day of the year. Any solution?
Asked
Active
Viewed 1,192 times
-3

Ali
- 33
- 6
-
Check out the lubridate package in R. – akaDrHouse May 20 '17 at 04:12
-
Or you could use the `weekdays` function from base R, `weekdays(as.Date(g, format = "%m/%d/%y"))` – Ronak Shah May 20 '17 at 04:57
1 Answers
1
You could use the format function with %a or %A
date <- as.Date("2017-05-20")
format(date, "%A")
[1] "Saturday"
format(date, "%a")
[1] "Sat"
If your original date is in the format "07/29/05" in the column A$Date you can call
strDays <- format(as.Date(A$Date, "%m/%d/%y"), "%A")

Harald Gliebe
- 7,236
- 3
- 33
- 38
-
Could you be a bit more specific on how can I add the column `Date` here. The format is 07/29/05. I guess I`ll need to convert it to 2005-07-29 format. – Ali May 20 '17 at 04:26
-
-