作者poker0531 (破壳)
看板R_Language
标题[问题] 依日期选别栏位的值
时间Sun Aug 5 15:45:59 2018
[问题类型]:
程式谘询(我想用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
[关键字]:
台指期结算日判断
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 61.231.198.107
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1533455164.A.0A2.html
※ 编辑: poker0531 (111.248.204.103), 08/06/2018 13:28:55
※ 编辑: poker0531 (111.248.204.103), 08/06/2018 13:29:21
1F:→ clansoda: 第三个周三其实不难,只是交割年月是什麽 08/06 19:31
2F:→ poker0531: 第三个周三, 然後没有交易资料的话要顺延到下一个交易 08/07 10:30
3F:→ poker0531: 日 08/07 10:30
4F:→ poker0531: Sorry我没表达清楚, 下一篇有做补充说明, 希望更完整 08/07 10:31