should help you out I'm looking to see if there is a quicker way to replace the days of the week in a R dataframe with a number. Essentially, the question I'm wondering is given one vector and a corresponding vector is there a quick way to apply a replacement to a dataframe. , Create a index of weekdays and match with the day_of_week column.

code :

```
Date <- as.Date('2014-12-29') #Monday
Wdays <- weekdays(seq(Date, length.out=7, by= '1 day'))
df[,2] <- match(df[,2],Wdays)
df[,2]
#[1] 2 3 4 5 6 7
```

```
as.numeric(factor(df$day_of_week, levels=c("Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday", "Sunday")))
#[1] 2 3 4 5 6 7
```

```
Un <- c('Tuesday', 'Wednesday', 'Thursday', 'Friday',
'Saturday', 'Sunday', 'Monday')
days_num <- c(2,3,4,5,6,7,1)
set.seed(24)
day_of_week <- sample(Un, 20, replace=TRUE)
unname(setNames(days_num, Un)[day_of_week])
#[1] 4 3 6 5 6 1 3 7 7 3 6 4 6 6 4 1 3 2 5 2
```

```
library(qdap)
as.numeric(mgsub(Un, days_num, day_of_week))
#[1] 4 3 6 5 6 1 3 7 7 3 6 4 6 6 4 1 3 2 5 2
```

```
library(qdapTools)
day_of_week %l% data.frame(Un, days_num)
#[1] 4 3 6 5 6 1 3 7 7 3 6 4 6 6 4 1 3 2 5 2
```