å¹´é50è¨äºæ¸ãã«ã¯ãã¨3ã¶æã§32è¨äºæ¸ããªãã¨ãããªã
â¦â¦ãã¸ã§ï¼ç®æ°ã§ããªãã«ãç¨ãããã
ãããã3ã¶æã§30è¨äºæ¸ãã£ã¦ãã¨ã¯ã1ã¶æ10è¨äºâ¦â¦
ãã¿ãæ¢ããªãã¨ãªãã¨æãã¾ããããç´è¿ã¯ããã¤ãããã®ã§ããããï¼
ååã®ãããã
ãããªè¨äºãååæ¸ãã¾ããã
ç§éã¯Rããã¯ã¼ãã³ã°ãã£ã¬ã¯ããªã確èªã§ãã
ããã«ãããã¡ã¤ã«é¡ã確èªã§ãã
æ°ãããã©ã«ããä½æãããã¨ãã§ããããã«ãªãã¾ããã
ã¨æã£ããããã®é±ã®TokyoRã§ãéå¶ã®æ¹ã«ããåå¿è
ã»ãã·ã§ã³ã§åãä¸ãã¦ããã ãã¾ãã*1ã
ã¹ã©ã¤ãã¯è¿ããã¡ã«å
¬éãããã§ãããã
ãã¨ã¯ã¨ããã°ããã¬ãã¨ã®åæãªåé¡æèã ã£ãã®ã§ãããã³ãã¥ããã£ã®éå¶ã®æ¹ãæ¾ã£ã¦ãã ããã
ãã®éè¦æ§ã¨æ¹æ³è«ã«ã¤ãã¦ãªã¼ãã³ã«ãã¦ããããã¨ããã®ãã¨ã«ã¯å¤§ããªæ義ããããªãã¨èãã¦ãã¾ãã
ããã°ã©ã è¨èªã³ãã¥ããã£ã¨ãã¦ãITé å以å¤ã®ã¦ã¼ã¶ãå¤ãã¨ããç¹å¾´ã¯ã大å¤ã«ç¹æ®ã§ãã
ããæ
ã«ãã¨ã³ã¸ãã¢ãªã³ã°ã§ã¯ã常èãã¨ãªããããªãã¨ã浸éãã¥ããå´é¢ãããã
ãããæ¥åã®å¹çãåç¾æ§ãªã©ã«æ¯éããããè¦å ã«ãªãããå ´é¢ããããã¨ããåé¡æèãããã¾ãã
ããã¦ãã®åé¡ã¯ãç°¡åãªã³ãã¨ããã¤ãã®åºæ¬çãªé¢æ°ã§è§£æ±ºã§ããåé¡ãªã®ã§ã
解決ããããããªãããã¨ããã¢ããã¼ã·ã§ã³ã§ãã
ã¡ãªã¿ã«ãå¿ç¨çãªç®¡çæ¹æ³ã¯ã以ä¸ã®ã¹ã©ã¤ãããã¡ããã¡ãæå¹ã§ãã
ä»åã®ã話
ãã©ã«ãã管çã§ãã¦ãããã¡ã¤ã«åããããã«ãããçµ±ä¸æã®ãªãååã§ããã¨å ¨ããã£ã¦æå³ãããã¾ããã
ãããç¨åº¦åãããããæ§æãã¯ååã示ããã¨ããã§ãããä¾ãã°ä»¥ä¸ã§ãã
åæããã¸ã§ã¯ã â å ¥åãã¼ã¿ | â 20200806_å®é¨ãã¼ã¿.csv | â 20200807_å®é¨ãã¼ã¿.csv | â 20200808_å®é¨ãã¼ã¿.csv â åºåãã¼ã¿ | â csvãã¡ã¤ã« | | â 20200806_140340_å®é¨å帰åæçµæ.csv | | â 20200807_143040_å®é¨å帰åæçµæ.csv | | â 20200808_145520_å®é¨å帰åæçµæ.csv | â ã°ã©ã | | â 20200808_153422_å帰ç´ç·.png | | â 20200808_173006_æ®å·®ãããã.png â ã½ã¼ã¹ã³ã¼ã | â 20200805_åå¦çèªåå.R | â 20200806_å帰åæ.R | â 20200807_å帰åæ.R | â 20200808_å帰åæ.R â å®é¨ç®¡ç | â åæå®æ½è¨é².**txt**
ããã¦ããã¡ãªä¾ã¯ãã¡ãã§ãã
åæããã¸ã§ã¯ã â å ¥åãã¼ã¿ | â å®é¨ãã¼ã¿.csv | â å®é¨ãã¼ã¿_ãªããä¿®æ£.csv | â å®é¨ãã¼ã¿_æçµç.csv â åºåãã¼ã¿ | â csvãã¡ã¤ã« | | â å®é¨çµæ.csv | | â å®é¨çµæ_ä¿®æ£ç.csv | | â å®é¨çµæ_å 輩.csv | â ã°ã©ã | | â ã°ã©ã_ããã.png | | â ã°ã©ã_æ¯è«.png â ã½ã¼ã¹ã³ã¼ããã¡ãã§ãã | â åå¦ç.R | â åæ.R | â åæ_ä¿®æ£.R | â åæ_æ¬çª.R â å®é¨ç®¡ç | â åæå®æ½è¨é².txt
ããã§ã¯ãããã¾ããããä½ããããªãã®ãâ¦â¦
- ãã¤ãã£ãã®ããåãããªã
- ä½ããã£ãã®ãåãããªã
- ä½ãåºåããã¦ããã®ããããããªã
ãããããªãã§ãããã©ãã«ããªããã®ãã
ã©ãã«ããªãã¾ãããããRãªããã
ç¹å®ã®æååãå«ããã¡ã¤ã«ãæ¤ç´¢ãã
æååã®æ¤ç´¢ã«ã¯ grep()
é¢æ°ãªã©ã使ããã¨ãã§ãã¾ãã
ä»ãç§éã¯ä¸è¨ã®ãåæããã¸ã§ã¯ãããã£ã¬ã¯ããªã«ãã¦ã
2020å¹´8æ8æ¥ã®å®é¨çµæãåç
§ãããã¨ãã¾ãã
ãã®æã¯ãä¾ãã°ä»¥ä¸ã®ãããªæãã
getwd() # åºåä¾ã¯ãããªæã > "C:/Users/Documents/åæããã¸ã§ã¯ã" # ãã©ã«ãã®å ¨ã¦ã®ãªã¹ãã確ä¿ãã output_file_list <- list.files("./åºåãã¼ã¿/csvãã¡ã¤ã«") # ãã®ãã¡ã"20200808"ãå«ã¾ãããã¡ã¤ã«ãåºåãã output_0808 <- output_file_list[grep("20200808", output_file_list)] output_0808 # åºåä¾ã¯ãããªæã > [1] "20200807_143040_å®é¨å帰åæçµæ.csv" "20200808_145520_å®é¨å帰åæçµæ.csv"
grep()
é¢æ°ã¯ããã®æååãå«ã¾ãããªã¹ãããä½çªç®ã«ãããããæ°åã§çãã¦ããã¾ãã
ã§ãã®ã§(æ°æã¡æªãã§ãã)ãå
¨ãªã¹ãã®ãã¡ãã20200808ããå«ã¾ãããã¡ã¤ã«ã®è¦ç´ ãã ããåãåºãã
ã¨ããæä½ã§ãã¡ã¤ã«ãè¦ã¤ãã¦ãã¾ããæ°æã¡æªããã§ãè¿ã£ã¦ããã°ããã®ã§ãã
ããã§ãæã
ã¯ãè¦åæ§ã®ããããã¡ã¤ã«åã§ããã°ã
ãã®è¦åãæå®ãããã¨ã§ãã¡ã¤ã«ãæ¤ç´¢ãããã¨ãã§ããå¯è½æ§ãæã«ãã¾ããã
ã§ãããè¦åæ§ã®ãããã¡ã¤ã«åãã¤ããã®ã¯äººéã§ãã
人éã¯è¦åæ§ã®ãããã¡ã¤ã«åããã¡ãã¡ééããã«ä»ä¸ãããã¨ã¯ã¨ã¦ãè¦æã§ãã
è¦æã§ãªããã°ãã¬ãã¨ã¯ãããªè¨äºãæ¸ãã¦ãã¾ããã
å½åè¦åãå®ç¾©ãã
ã³ã³ãã¥ã¼ã¿ã¯ãè¦åçãªæ§é ããå¦çãããã¨ãé常ã«å¾æã§ãã
ã³ã³ãã¥ã¼ã¿ãæ¢ããããååã«ããã¨ãããã¤ã®ãã¼ã¿ãåç
§ãããããã
ãã©ã®åæãåç
§ããããããããªãã®åºåçµæã確èªãããããã
ãªã©ãæ¢ãããããªãã¾ãã
ããã«ããããæ£è§£ã ãã¨ããæ確ãªæ£è§£ã¯å®éã®ã¨ããããã¾ããã
å°ãªãã¨ãããã¤ãã£ãããã®æè¨ã¯ããç¨åº¦åºãåæããããã¨æã£ã¦ãã¾ããã
ãã¨ãã°ãã©ã®åæããã¯ãã©ã®ç¨åº¦ã®è©³ããã§æ¸ãå¿
è¦ãããã®ãã¯ããã¸ã§ã¯ãã«å¼·ãä¾åãã¾ãã
ããã¸ã§ã¯ãã«ãã£ã¦ã¯ãå帰åæãã¨åããã°ãããã®ãããã°ããã¢ã½ã³å帰ã¢ãã«ãã§ããã¨ããã¾ã§åããå¿
è¦ãããå ´é¢ããããã
ãåå¦çãã¿ã¼ã³1ã使ã£ããã¸ã¹ãã£ãã¯å帰åæããªã©ãããç´°ãããã¡ã¤ã«åãå¿
è¦ããç¥ãã¾ããã
ããã¯ãã©ããããã®è©³ããã§å½åè¦åãå®ããããã¨ãã©ããããå®é¨ç®¡çè¨é²ã§ç®¡çããããã®åé¡ãªã®ã§ã
ã¿ããªã§è©¦è¡é¯èª¤ãã¦æ±ºãã¾ãããã
ä»åã¯ãè¦åæ§ã®ããååãéè¦ã§ãããã¨ãã話ãä¼ããã°ããã®ã§ãæä½éã®æ
å ±ã§ã³ã³ããã¼ã«ãã¾ãã
æ¥ä»ãæå»ãåå¾ãã with R
Rã§ä»æ¥ã®æ¥ä»ãç¥ãããå ´åã Sys.Date()
é¢æ°ã使ãã¾ãã
Sys.Date() > "2020-09-19"
ã¨ã¦ãç°¡åã§ããããï¼ãæå»ãåå¾ããããï¼
ãããªã¨ã㯠format
é¢æ°ã¨ Sys.time()
é¢æ°ãçµåãã¦ä½¿ãã¾ãããã
ã¡ãªã¿ã«åç´ã« Sys.time()
ã使ãã¨ä»¥ä¸ã®ãããªå¤ãè¿ã£ã¦ãã¾ãã
Sys.time() > "2020-09-19 16:07:39 JST"
ããã§ãããã§ããããã£ã¨èªç±ã«æé表è¨ãæãåºãããã§ãã
ãããªã¨ãã« format
é¢æ°ã使ãã¨ä¾¿å©ã
nowtime <- format(Sys.time(), "%H:%M:%S") nowtime > "16:08:54" # å®è¡ããæã®æé
ããã§ã ""
ã§ããã£ãæååã®ä¸ã« %
ã¨ãããã®ãããã¾ããã
ãã㯠format
é¢æ°ã§è¡¨ç¾ããéã«ãã©ã®æéåä½ãå½ã¦ã¯ããããæå®ãããã¼ã¨ãã¦ã
ç¶ãã¢ã«ãã¡ããããç¨ããã¨ãã宣è¨ã®ããã®æ¼ç®åã§ãã
ãä½æã㯠H
ããä½åã㯠M
ãããã¦ãä½ç§ã㯠S
ã§æå®ãã¾ãã
%
ããªãå ´åã¯ãããããæååã¨ãã¦è¡¨ç¾ããã¾ãã
ãã以å¤ã«ãããããã®ã¢ã«ãã¡ãããã«ãã£ã¦åºåã®ä»æ¹ãæå®ã§ãã¾ãã
ãã¡ããæ¥æ¬èªã§ãããããã調ã¹ã¦ããã£ã¦ã¿ã¦ãã ããã
åºæ¬çã«ãSys.Date()
㯠format(Sys.time(), %y-%m-%d)
ã¨ç価ã§ããTPOã¨ãã§ä½¿ãåãã¾ãããã
æååãã¤ãªãã
Rã«ã¯ paste()
é¢æ°ãããã¾ãã,
ã§æååãåºåãã ãã§æååãçµåãã¦ããã¾ãã
ããã§ãæ¥ä»+åæåããä½æã§ãã¾ããã
Exp_day <- Sys.Date() Exp_name <- "å帰åæ" file_name <- paste(Exp_day, Exp_name, sep = "_") ## åºåä¾ file_name > [1] "2020-09-19_å帰åæ"
sep
ã¯ãæååã®åºåãã¨ãã¦ä½¿ãè¨å·ãæå®ã§ãã¾ããä»åã¯ã¹ã¿ã³ãã¼ãã« _
ãæå®ãã¾ããã
ããããæè»ã«æååãçµåã§ããé¢æ°ã« paste0()
é¢æ°ãããã¾ãããã¬ãã¨ã¯ãã£ã¡æ´¾ã§ãã
Exp_day <- Sys.Date() Exp_name <- "å帰åæ" file_name <- paste0(Exp_day, "_", Exp_name) ## åºåä¾ file_name > [1] "2020-09-19_å帰åæ"
ãã¤ãªãããé ã«ä¸¦ã¹ããã ãããªãã¦ã·ã³ãã«ãªãã ããã¨ã¯ä¸ã« .csv
ã¨ãã¤ããã°è¯ãã®ã§ãã
ä¾ãã° model
ã¨ããååã§å帰åæã®çµæãä¿æãã¦ããã¨ãã¾ãã
以ä¸ã®ãããªå½¢ã§ãåºåçµæãç¶ãã¹ãå ´æã«æ ¼ç´ã§ãã¾ãã
ç¸å¯¾ãã¹ã¨ãã®æ
å ±ã¯ãã³ã¿ããããã®ã¹ã©ã¤ãããåã®è¨äºãåç
§ãã¦ãã ããã
output_name <- paste0("./åºåãã¼ã¿/csvãã¡ã¤ã«/",file_name, ".csv") write.csv(model, output_file, row.names = FALSE)
ãããªæãã§ãè¦åæ§ã®ãããã¡ã¤ã«åãæåã«å®ç¾©ãã¦ãã¾ãã¨ã
è¦åæ§ã®ããå½¢ã§åºåãããã¨ãå¯è½ã§ããï¼ã¹ããï¼
ãï¼ããã¡ãã¡æ¥ä»ãæå»ãå¼ã³åºãã¦ããã¡ã¤ã«åä½ãã®ããã©ãããï¼ã
é¢æ°åãã¡ããã°ãããããªãâ¦â¦
*2
次åäºå
ããã¾ã§1å1åãRã®ã³ã³ã½ã¼ã«ã«ã¶ãæãã¦è¡ãæ¹æ³ã§ãããã
ãã¡ãããããã¯èªååãããã¨æãã®ã人éã次åã¯ãããªã話ã
- ã¤ã³ãããã¨ã¢ã¦ããããã®ãã©ã«ããæå®ãã¡ããé¢æ°ãä½ã£ã¡ãã
- ãããå¼ã³åºããã(
source()
ã¡ã½ãã)
- ãããå¼ã³åºããã(
- ã¤ã³ãããããã¢ã¦ããããã¾ã§ã®ä¸é£ã®æµããé¢æ°ã«ãã¦ãã¾ã
- åæããæ¹æ³ããã¼ã¿ãã¢ã¦ããããã®å½¢å¼ãå ¨é¨å®ã¾ã£ã¦ããå ´å
- æ¢ç´¢çãªåæå ´åã®å½åè¦åã¯ã©ãããã°ããã®ï¼
- æ¢ç´¢ãã¿ã¼ã³ãåæãããå¥ã«åºåãã
- ãåæããã¸ã§ã¯ããã®æ¡å¼µ