Home > Mobile >  How to transform database weekday name to system weekday name
How to transform database weekday name to system weekday name

Time:12-23

I have a database with dates and the corresponding day of the week. However, I would like to know if it is possible to change the days of the week names of this database for the the system's weekdays names, that is, instead of being wednesday day it would be Wednesday, which is the form that is in the system. I believe I would have to use the wkday function somehow

df1 <- structure(
  list(date = c("2021-06-23","2021-06-24","2021-06-30","2021-07-01"),
       Week= c("wednesday day","thursday day","wednesday day","thursday day")),
  class = "data.frame", row.names = c(NA, -4L))

CodePudding user response:

It would look something like this. The weekdays() function is used to give a date and get the day of the week back.

df1$Week <- weekdays(df1$date)

Working reproduction:

df1 <- structure(
    list(date = c("2021-06-23","2021-06-24","2021-06-30","2021-07-01"),
         Week= c("wednesday day","thursday day","wednesday day","thursday day")),
         class = "data.frame", row.names = c(NA, -4L))

df1$date <- as.Date(df1$date)

df1$Week <- weekdays(df1$date)

df1
  •  Tags:  
  • r
  • Related