Eva*_*Eva 10 time r date range
我想生成一个包含该范围内所有业务日期的时间序列:
startDate = "1990-01-01"
endDate = "1990-12-31"
Run Code Online (Sandbox Code Playgroud)
例如"1990-01-01","1990-01-02",......
Osc*_*ñán 14
@csgillespie:chron提供功能is.weekend:
days = seq(as.Date("1990-01-01"), as.Date("1990-12-31"), by="1 day")
library(chron)
weekDays = days[!is.weekend(days)]
## let's check the result with the function weekdays
weekdays(weekDays)
Run Code Online (Sandbox Code Playgroud)
此外,您可以在不chron使用的情况下获得相同的结果format:
isWeekend <- function(x) {format(x, '%w') %in% c(0, 6)}
weekDays2 = days[!isWeekend(days)]
Run Code Online (Sandbox Code Playgroud)
您只需使用该seq命令即可.例如,
##Specify you want 10 dates starting on 1990-01-01
R> seq(as.Date("1990-01-01"), length.out=10, by="1 day")
[1] "1990-01-01" "1990-01-02" "1990-01-03" "1990-01-04" "1990-01-05"
[6] "1990-01-06" "1990-01-07" "1990-01-08" "1990-01-09" "1990-01-10"
Run Code Online (Sandbox Code Playgroud)
要么
##Specify the start and end with increment
R> seq(as.Date("1990-01-01"), as.Date("1990-01-10"), by="1 day")
[1] "1990-01-01" "1990-01-02" "1990-01-03" "1990-01-04" "1990-01-05"
[6] "1990-01-06" "1990-01-07" "1990-01-08" "1990-01-09" "1990-01-10"
Run Code Online (Sandbox Code Playgroud)
要获得工作日,您可以使用该chron库:
days = seq(as.Date("1990-01-01"), as.Date("1990-12-31"), by="1 day")
library(chron)
weekDays = days[!is.weekend(days)]
Run Code Online (Sandbox Code Playgroud)