営業日の日付差を計算する、つまりExcelのネットワーク日付機能のような週末を除外するのに問題がある。R:営業日の差異を見つける
ここは私のデータです。
e <- structure(list(date.pr = structure(c(15909, 15933, 16517, 15961, 15974, 15978), class = "Date"), date.po = structure(c(15909, 15933, 15954, 15961, 15974, 15978), class = "Date")), .Names = c("date.1", "date.2"), class = c("tbl_df", "data.frame"), row.names = c(NA, -6L))
このタスクの「bizdays」パッケージが見つかりました。どちらがうまくいくのでしょうか。
> bizdays(e$date.2,e$date.1)
[1] 0 0 563 0 0 0
しかし、私のデータには、日付2が日付1より前の場合が含まれます。
e2 <- structure(list(date.pr = structure(c(15909, 15933, 16517, 15961, 5974, 15978, 15978), class = "Date"), date.po = structure(c(15909, 15933, 15954, 15961, 15974, 15978, 15979), class = "Date")), .Names = c("date.1", "date.2"), class = c("tbl_df", "data.frame"), row.names = c(NA, -7L))
今では、次のエラー得られます。
> cal <- Calendar(holidaysANBIMA, weekdays=c("saturday","sunday"))
> bizdays(e2$date.2,e2$date.1,cal)
Error in bizdays.Date(e2$date.2, e2$date.1, cal) :
All from dates must be greater than all to dates.
を私はifelse()のロジックを使用して考えていますが、それは私に同じエラーを与えます。
> ifelse(e2$date.2 < e2$date.1, NA, bizdays(e2$date.2,e2$date.1,cal))
Error in bizdays.Date(e2$date.2, e2$date.1, cal) :
All from dates must be greater than all to dates.
ヘルプありがとうございました。
http://stackoverflow.com/questions/4559175/r-finding-difference-between-business-daysは、問題を解決しました。 – woshishui