Home > Blockchain >  The wday functionality in lubridate
The wday functionality in lubridate

Time:06-24

Could someone explain in simple terms what wday in R does.

E.g:

df$date[wday(df$date, week_start=1)==7] <- df$date[wday(df$date, week_start=1)==7]-1

CodePudding user response:

Assuming you are talking about the wday function from the package "lubridate", it takes a date and returns the day of the week that date fell on:

> library(lubridate)
> date = as.Date('1592-03-14')
> wday(date)
[1] 7

It has options to change the first day of the week, and to give output in words instead:

> library(lubridate)
> date = as.Date('1592-03-14')
> wday(date, label = TRUE, abbr = FALSE)
[1] Saturday
7 Levels: Sunday < Monday < ... < Saturday
>
> wday(date, label = TRUE, abbr = FALSE, week_start = 1)
[1] Saturday
7 Levels: Monday < Tuesday < ... < Sunday

Basic function information like this is readily available in a package's documentation to save having to wait for an answer in future.

  •  Tags:  
  • r
  • Related