I have a data frame with records from the month of October 2017. Column 6 has the dates as a character vector.
This is what it looks like:
> october2017[1:6,1:6]
V1 V2 V3 V4 V5 V6
1 89108060 IN0000005 P2 RK1 CA1-R 10/1/2017
2 10503818 IN0000014 P2 RK1 CA31 10/2/2017
3 89108152 765000054 P2 RK1 CA31 10/3/2017
4 89108152 765000197 P2 RK1 CA31 10/4/2017
5 89108206 200000162 P2 RK1 CA31 10/5/2017
6 89108206 100001098 P2 RK1 CA31 10/6/2017
> class(october2017$V6)
[1] "character"
The actual data frame is much larger than this. What I want to do is create a new column to denote the day of the week that matches each date and add it to the data frame. If the date is "10/1/2017" I want the new column denoting the day of the week to show "Sunday" in that row.
This is what I want the data frame to look like:
> october2017[1:6,1:7]
V1 V2 V3 V4 V5 V6 V7
1 89108060 IN0000005 P2 RK1 CA1-R 10/1/2017 Sunday
2 10503818 IN0000014 P2 RK1 CA31 10/2/2017 Monday
3 89108152 765000054 P2 RK1 CA31 10/3/2017 Tuesday
4 89108152 765000197 P2 RK1 CA31 10/4/2017 Wednesday
5 89108206 200000162 P2 RK1 CA31 10/5/2017 Thursday
6 89108206 100001098 P2 RK1 CA31 10/6/2017 Friday
This is what I tried: newcol = weekdays(as.Date(october2017$v6, format="%m/%d/%Y")) october2017 = cbind(october2017,newcol, stringsAsFactors=FALSE)
This is the error message I get when I try to run the first line of this code: Error in as.Date.default(october2017$v6, format = "%m/%d/%Y") : do not know how to convert 'october2017$v6' to class “Date”
Can anyone help me understand why this is happening?