[問題類型]:
程式諮詢(我想用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
[關鍵字]:
台指期結算日判斷