看板 R_Language 關於我們 聯絡資訊
[問題類型]: 程式諮詢(我想用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://www.ptt.cc/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
clansoda: 第三個週三其實不難,只是交割年月是什麼 08/06 19:31
poker0531: 第三個週三, 然後沒有交易資料的話要順延到下一個交易 08/07 10:30
poker0531: 日 08/07 10:30
poker0531: Sorry我沒表達清楚, 下一篇有做補充說明, 希望更完整 08/07 10:31