【发布时间】:2013-02-14 21:27:05
【问题描述】:
我知道开始日期start 和最后日期maturity。如何在不考虑周末日期的情况下填写带有日期的向量?
例如,假设:
> start = as.Date("2013-02-28");
> maturity = as.Date("2013-03-07");
我想得到以下向量作为结果:
results
[1] "2013-03-01" "2013-03-04" "2013-03-05" "2013-03-06" "2013-03-07"
> start = as.Date("2013-02-28");
> maturity = as.Date("2013-03-07");
> x <- seq(start,maturity,by = 1)
> x
[1] "2013-02-28" "2013-03-01" "2013-03-02" "2013-03-03" "2013-03-04" "2013-03-05"
[7] "2013-03-06" "2013-03-07"
> x <- x[!weekdays(x) %in% c('Saturday','Sunday')]
> x
[1] "2013-02-28" "2013-03-01" "2013-03-02" "2013-03-03" "2013-03-04" "2013-03-05"
[7] "2013-03-06" "2013-03-07"
同样的结果...?
【问题讨论】: