How to determine if date is a weekend or not (not using lubridate)

前端 未结 7 865
予麋鹿
予麋鹿 2020-11-29 12:00

I have a vector of date objects (yyyy-mm-dd) and I want to determine if any of them are on weekend or not. Is there a function that can determine this straighta

7条回答
  •  悲哀的现实
    2020-11-29 12:36

    After looking a lot about this topic, I found this solution particularly simple using the package RQuantLib

    install.packages("RQuantLib")
    library(RQuantLib)
    isBusinessDay(calendar="WeekendsOnly", dates=yourdatesofinterest)
    

    You can modify this code with different calendars to add to the weekends different sets of holidays in different countries (below just an example, but they have many more).

    isBusinessDay(calendar="UnitedStates", dates=yourdatesofinterest)
    isBusinessDay(calendar="UnitedStates/Settlement", dates=yourdatesofinterest)
    isBusinessDay(calendar="UnitedStates/NYSE", dates=yourdatesofinterest)
    isBusinessDay(calendar="Sweden", dates=yourdatesofinterest)
    isBusinessDay(calendar="Mexico", dates=yourdatesofinterest)
    

    I hope it helps somebody

提交回复
热议问题