Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The wday functionality in lubridate

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading