R时间序列数据,仅限每日工作日
我正在使用以下代码:R时间序列数据,仅限每日工作日,r,date,sequence,R,Date,Sequence,我正在使用以下代码: dates<-seq(as.Date("1991/1/4"),as.Date("2010/3/1"),"days") 日期这对你有用吗?(注意,它需要安装timeDate软件包) #install.packages('timeDate')) 要求(时间日期) #“timeDate”序列 tS您输入的日期不正确。为了使用YYYY/DD/MM输入模式(1991/1/4为星期一),您需要在as.Date中有一个格式字符串 因此,假设要排除周末,完整的解决方案是: 我是在查
dates<-seq(as.Date("1991/1/4"),as.Date("2010/3/1"),"days")
日期这对你有用吗?(注意,它需要安装timeDate软件包)
#install.packages('timeDate'))
要求(时间日期)
#“timeDate”序列
tS您输入的日期不正确。为了使用YYYY/DD/MM输入模式(1991/1/4为星期一),您需要在as.Date中有一个格式字符串
因此,假设要排除周末,完整的解决方案是:
我是在查找工作日函数时遇到这个问题的,因为OP请求的是“工作日”而不是“工作日”,而且timeDate
也有isBizday
函数,所以这个答案使用该函数
# A timeDate Sequence
date.sequence <- timeSequence(as.Date("1991-12-15"), as.Date("1992-01-15")); # a short example period with three London holidays
date.sequence;
# holidays in the period
years.included <- unique( as.integer( format( x=date.sequence, format="%Y" ) ) );
holidays <- holidayLONDON(years.included) # (locale was not specified by OP in question nor in profile, so this assumes for example: holidayLONDON; also supported by timeDate are: holidayNERC, holidayNYSE, holidayTSX & holidayZURICH)
# Subset business days
business.days <- date.sequence[isBizday(date.sequence, holidays)];
business.days
#时间日期序列
date.sequence好的,你的意思是不包括周末?查看函数平日
@BrunoGG,不客气。当您的问题解决后,重新编号以将您的问题标记为已解决。谢谢您!然而,我似乎得到了包括周末在内的每日数据。@BrunoGG检查工作日(X)的打印输出。你可能会在工作日用另一种语言,这对你的假期非常有帮助。对编制自定义假日列表(如感恩节后一天)有何建议。?
X <- seq( as.Date("1991/1/4", format="%Y/%m/%d"), as.Date("2010/3/1", format="%Y/%m/%d"),"days")
weekdays.X <- X[ ! weekdays(X) %in% c("Saturday", "Sunday") ]
# negation easier since only two cases in exclusion
# probably do not want to print that vector to screen.
str(weekdays.X)
> table(weekdays(weekdays.X) )
Friday Monday Thursday Tuesday Wednesday
1000 1000 999 999 999
# A timeDate Sequence
date.sequence <- timeSequence(as.Date("1991-12-15"), as.Date("1992-01-15")); # a short example period with three London holidays
date.sequence;
# holidays in the period
years.included <- unique( as.integer( format( x=date.sequence, format="%Y" ) ) );
holidays <- holidayLONDON(years.included) # (locale was not specified by OP in question nor in profile, so this assumes for example: holidayLONDON; also supported by timeDate are: holidayNERC, holidayNYSE, holidayTSX & holidayZURICH)
# Subset business days
business.days <- date.sequence[isBizday(date.sequence, holidays)];
business.days