-1

In my data frame table, the days of the week are integer type. I want to change the days of the week, for example Monday, Tuesday.

I tried stringr::str_replace()

Peter
  • 11,500
  • 5
  • 21
  • 31
  • It would be helpful if you could provide a sample data using `dput(x)` refer https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Nad Pat Mar 26 '22 at 07:46

1 Answers1

2

Please try to capture sample data and desired output next time. I will try based on provided info.

  1. Simple Approach : Lets say your data has a column weekday with integer values, similar to this- added data just for sample:

    df <- data.frame(
       days_n =c(1,2,3,4,5,6,7)
       ,SomeData = c('A','AA','BB','CC','BB','AAA','CCC'))
    

Then just mutate using wonderful lubridate

df%>%mutate(Weekday = wday(x = days_n,label = T,abbr = T))

will give you :

 days_n SomeData Weekday
1      1        A     Sun
2      2       AA     Mon
3      3       BB     Tue
4      4       CC     Wed
5      5       BB     Thu
6      6      AAA     Fri
7      7      CCC     Sat

Check wday() in lubridate for more.

anuanand
  • 400
  • 1
  • 9