我有一个包含每日数据的数据框(创造性地命名为data1)。如果该行(日)是假日,我需要一列假期。列日期的格式为日期,列和YEAR是一个因子;
> str(data1$date)
Date[1:3645], format: "2007-09-06" "2007-09-07"
我已经加载了timeDate包,希望能够使用它。我尝试了以下作为例子;
data1$holiday[data1$date == USDecorationMemorialDay(year = data1$YEAR)] <- "memday"
但是我收到此错误消息;
Error in `==.default`(data1$date, USDecorationMemorialDay(year = data1$YEAR)) :
comparison (1) is possible only for atomic and list types
In addition: Warning messages:
1: In `[<-.factor`(`*tmp*`, data1$date == USDecorationMemorialDay(year = data1$YEAR), :
invalid factor level, NA generated
2: In Ops.factor(year, 10000) : ‘*’ not meaningful for factors
感谢任何帮助,谢谢。
编辑:
这是我的数据框的输入;
> dput(droplevels(head(data1[c("date", "holiday", "YEAR")])))
structure(list(date = structure(c(13762, 13763, 13764, 13765,
13766, 13767), class = "Date"), holiday = c("NO", "NO", "NO",
"NO", "NO", "NO"), YEAR = c(1, 1, 1, 1, 1, 1)), .Names = c("date",
"holiday", "YEAR"), row.names = 6:11, class = "data.frame")