📅  最后修改于: 2022-03-11 14:52:00.357000             🧑  作者: Mango
x <- seq(Sys.Date(), by = "1 day", length.out = 21)
data.frame(
x = x,
weekday = weekdays(x),
next_friday = ceiling_date(x, "week") +
ifelse(weekdays(x) %in% c("Saturday", "Sunday"), 5, -2)
)
## x weekday next_friday
## 1 2014-11-17 Monday 2014-11-21
## 2 2014-11-18 Tuesday 2014-11-21
## 3 2014-11-19 Wednesday 2014-11-21
## 4 2014-11-20 Thursday 2014-11-21
## 5 2014-11-21 Friday 2014-11-21
## 6 2014-11-22 Saturday 2014-11-28
## 7 2014-11-23 Sunday 2014-11-28
## 8 2014-11-24 Monday 2014-11-28
## 9 2014-11-25 Tuesday 2014-11-28
## 10 2014-11-26 Wednesday 2014-11-28
## 11 2014-11-27 Thursday 2014-11-28
## 12 2014-11-28 Friday 2014-11-28
## 13 2014-11-29 Saturday 2014-12-05
## 14 2014-11-30 Sunday 2014-12-05
## 15 2014-12-01 Monday 2014-12-05
## 16 2014-12-02 Tuesday 2014-12-05
## 17 2014-12-03 Wednesday 2014-12-05
## 18 2014-12-04 Thursday 2014-12-05
## 19 2014-12-05 Friday 2014-12-05
## 20 2014-12-06 Saturday 2014-12-12
## 21 2014-12-07 Sunday 2014-12-12