Two columns [say col1 and col5] of my data frame are containing days of the week such as Sunday, Monday, ....
I want to convert those columns to their respective indices such as '1' for 'Sunday, '2' for 'Monday', ... & so on. Currently, I'm using ifelse but I believe there might be an efficient way to do the same in R.
Sample code:
df$col1 = ifelse(df$col1=="Sunday",1,df$col1)
df$col1 = ifelse(df$col1=="Monday",2,df$col1)
....
df$col1 = ifelse(df$col1=="Saturday",7,df$col1)
And similar code for col5
df$col5 = ifelse(df$col5=="Sunday",1,df$col5)
df$col5 = ifelse(df$col5=="Monday",2,df$col5)
....
df$col5 = ifelse(df$col5=="Saturday",7,df$col5)
I tried looking for suitable function in lubridate package but couldn't find any.