[问题类型]:
程式咨询(我想用R 做某件事情,但是我不知道要怎么用R 写出来)
[软件熟悉度]:
新手(没写过程式,R 是我的第一次)
[问题叙述]:
我想筛选一串日期中每月的第三个周三, 并在这个日期之前和之后做[交割年月]的筛选
[程式范例]:
资料长这样:
Date Time 交割年月 成交时间 成交价格 成交数量(B+S)
1 2011-01-03 084500 201101 8450000 9000 24
2 2011-01-03 084500 201101 8450000 9000 2
3 2011-01-03 084500 201101 8450000 9000 2
4 2011-01-03 084500 201101 8450000 9000 6
5 2011-01-03 084500 201101 8450000 9000 2
6 2011-01-03 084500 201101 8450000 9000 2
结算日的判断方式有google到如下:
require(lubridate)
x<-day(unique("
Con<-function(x,y){
if(day(x)>=15 && day(x)<=21 && y==3){
"SettleDay"
}else if ((day(x)>=16 && day(x)<=22 && y==4)||
(day(x)>=17 && day(x)<=23 && y==5)||
(day(x)>=18 && day(x)<=24 && y==6)||
(day(x)>=20 && day(x)<=26 && y==1)||
(day(x)>=21 && day(x)<=27 && y==1)||
(day(x)>=22)){
"SettleDay"
}
}
感谢各位大神帮忙,搞了我两个周末了
[环境叙述]:
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=Chinese (Traditional)_Taiwan.950 LC_CTYPE=Chinese
(Traditional)_Taiwan.950 LC_MONETARY=Chinese (Traditional)_Taiwan.950
[4] LC_NUMERIC=C LC_TIME=Chinese
(Traditional)_Taiwan.950
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] lubridate_1.7.4
loaded via a namespace (and not attached):
[1] compiler_3.5.1 magrittr_1.5 tools_3.5.1 Rcpp_0.12.18
stringi_1.2.4 stringr_1.3.1
[关键字]:
台指期结算日判断