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

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

    The wday in both lubridate and data.table (yes, data.table has pretty much everything but the kitchen sink :-) both do a variation on:

    as.POSIXlt(x, tz = tz(x))$wday + 1 # lubridate
    as.POSIXlt(x)$wday + 1L            # data.table
    

    So you could, in theory, just do:

    as.POSIXlt("2014-10-18")$wday + 1
    ## [1] 7
    

    and then test for the weekend days as other answer(s) do.

提交回复
热议问题