我最近问了一个关于将一系列日期列入列表的问题:Create a list of time sequences from dates between 2 vectors。
下面代码的最后一行回答了我的问题:
{% block content %}
<form action='/register/' method='post' >{% csrf_token %}
</form>
{% endblock %}
但是,我只需要包含工作日,所以我再次使用library(timeDate)
Dates <- data.frame(Start = c("2014-05-09 10:48:00",
"2014-05-11 19:39:00",
"2014-10-09 08:52:00",
"2014-10-29 10:48:59",
"2014-11-13 03:08:00"),
End = c("2014-05-11 19:39:00",
"2014-05-12 07:05:00",
"2014-10-29 10:48:59",
"2014-11-13 03:08:00",
"2014-11-13 08:41:59"))
Date_List <- mapply(timeSequence, Dates$Start, Dates$End, by = "min")
函数:
timeDate
这会增加序列的每个部分是否在一个工作日内。我希望它返回列表中的序列,不包含任何非工作日部分(即,删除序列中library(lubridate)
Holidays <- c("2013-07-04", "2013-09-02", "2013-10-14", "2013-11-11", "2013-11-21", "2013-11-22", as.character(seq(ymd("2013-12-24"), ymd("2014-01-01"), "days")),
"2014-01-20", "2014-02-17", "2014-05-26", "2014-07-04", "2014-09-01", "2014-10-13", "2014-11-11", "2014-11-27", "2014-11-28", as.character(seq(ymd("2014-12-24"), ymd("2015-01-01"), "days")),
"2015-01-19", "2015-02-16", "2015-05-25", "2015-07-03", "2015-09-07", "2015-10-12", "2015-11-11", "2015-11-26", "2015-11-27", as.character(seq(ymd("2015-12-24"), ymd("2016-01-01"), "days")),
"2016-01-18", "2016-02-15", "2016-05-30", "2016-07-04", "2016-09-05", "2016-10-10", "2016-11-11", "2016-11-24", "2016-11-25", as.character(seq(ymd("2016-12-24"), ymd("2017-01-01"), "days")),
"2017-01-16", "2017-02-20", "2017-05-29", "2017-07-04", "2017-09-04", "2017-10-09", "2017-11-10", "2017-11-23", "2017-11-24", as.character(seq(ymd("2016-12-24"), ymd("2017-01-01"), "days")))
Holidays <- timeDate(as.Date(Holidays))
for (b in 1:length(Date_List)) {
Biz_Seq[[b]] <- isBizday(Date_List[[b]], Holidays)
}
的部分)。
在分组列表中,我没有在SO上找到任何关于此特定问题的内容。提前谢谢。
答案 0 :(得分:1)
我认为您并未尝试在列表的元素中对列表进行子集化,而是尝试将类timeDate
的向量。这可以简单地完成:
Biz_Seq <- lapply(Date_List, function(days) days[isBizday(days, Holidays)])