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

前端 未结 7 820
予麋鹿
予麋鹿 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:47

    You could use isWeekend from package timeDate. Hard to do more straightforward :). wday specify which days should be considered as weekdays. By default from Mondays to Fridays.

    > today <- isWeekend(Sys.Date(), wday = 1:5)
    if (as.logical(today)){
      print("YES")
    } else print("NO")
    

    From the documentation :

    ## Dates in April, currentYear:
       currentYear = getRmetricsOptions("currentYear")
       tS = timeSequence(
          from = paste(currentYear, "-03-01", sep = ""),
          to = paste(currentYear, "-04-30", sep = ""))
       tS
    
    ## Subset of Weekends:
       isWeekend(tS)
       tS[isWeekend(tS)]
    

    It works also with isWeekday.

    0 讨论(0)
提交回复
热议问题