简体   繁体   English

R timeDate isHoliday()无法识别自定义日期

[英]R timeDate isHoliday() wont recognize custom dates

I am trying to use the isHoliday() function in R's timeDate package. 我正在尝试在R的timeDate包中使用isHoliday()函数。 I create a timeDate object called ppa_holidays, which is a list of holidays: 我创建了一个名为ppa_holidays的timeDate对象,该对象是假期的列表:

years <- c(2012,2013,2014,2015)
ppa_holidays <- timeDate(c(USNewYearsDay(year=years), Easter(year=years), USMemorialDay(year=years), 
              USIndependenceDay(year=years), USLaborDay(year=years), USThanksgivingDay(year=years),
              USChristmasDay(year=years)))

Which gives: 这使:


> ppa_holidays
America/New_York
 [1] [2012-01-01] [2013-01-01] [2014-01-01] [2015-01-01] [2012-04-08] [2013-03-31] [2014-04-20]
 [8] [2015-04-05] [2012-05-28] [2013-05-27] [2014-05-26] [2015-05-25] [2012-07-04] [2013-07-04]
[15] [2014-07-04] [2015-07-04] [2012-09-03] [2013-09-02] [2014-09-01] [2015-09-07] [2012-11-22]
[22] [2013-11-28] [2014-11-27] [2015-11-26] [2012-12-25] [2013-12-25] [2014-12-25] [2015-12-25]

However, when I use isHoliday(), there are certain dates that return TRUE even though they are not in ppa_holidays, eg: 但是,当我使用isHoliday()时,即使它们不在ppa_holidays中,某些日期也会返回TRUE,例如:


> isHoliday(timeDate("2012-12-08"), holidays=ppa_holidays)
2012-12-08 05:00:00 
               TRUE 

What am I doing wrong here? 我在这里做错了什么?

It seems the isHoliday function is also checking that the day is a weekday. 似乎isHoliday函数也在检查isHoliday By default it assumes Sat and Sun are "holidays" (or really non-business days) and 12/8/2012 was a Saturday. 默认情况下,假设周六和周日为“假日”(或实际上是非工作日),而2012年12月8日为星期六。 You can change the business days to include all the days of the week with the wday= parameter 您可以使用wday=参数将工作日更改为包括一周中的所有天。

isHoliday(timeDate("2012-12-08"), holidays=ppa_holidays, wday=0:6)
# 2012-12-08 
#      FALSE 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM