推 cd12631: 把日期和時間切開各一欄 然後篩選時間 09/21 16:18
推 s3714443: 用lubridate看看? 09/21 18:31
→ clansoda: 用data.table最快 09/21 20:33
→ clansoda: dt[between(hour(time), 0, 3, incbounds = FALSE)] 09/21 20:35
→ clansoda: 我直接寫在PTT上的,有錯的話應該是括號逗號之類的錯了 09/21 20:35
→ clansoda: 喔 上面那個3要改成2 09/21 20:35
→ clansoda: 你有日期的type嗎? 我其實不太熟R的datetype 09/21 23:26
→ clansoda: 你的是字串? 09/21 23:26
推 clansoda: 因為hour要POXITlt才能跑,他轉不過去我不知道你的 09/21 23:33
→ clansoda: datatype 你可能要class看看 09/21 23:33
推 tan800630: 看字串形式的話 直接as.POSIXct(x) 試試? 09/21 23:35
→ celestialgod: 直接regular expression取00:xx:xx或是01:xx:xx的格 09/22 08:39
→ celestialgod: 式就好了,沒幾行 09/22 08:39
→ celestialgod: dat[grepl('0[01]:\\d{2}:\\d{2}',dat$time),] 09/22 08:41
→ obarisk: package lubridate 09/22 12:35
→ obarisk: nettes/lubridate.html 09/22 12:35
→ obarisk: dat %>% mutate(hr=hour(ymd_hms(datecol))) %>% filter( 09/22 12:37
→ obarisk: hr==1) 09/22 12:37
→ celestialgod: 本身就是字串還是回歸字串處理吧XDD,感覺原po也不 09/22 18:44
→ celestialgod: 熟轉型 09/22 18:44
→ clansoda: 重點是他人不見了吧,只要把字串轉完剩下的都差不多 09/22 19:03
→ tony1331: 不好意思哦,有點忙,我是已經轉成時間了,我再試看看, 09/22 19:18
→ tony1331: 謝謝大家。 09/22 19:18
→ clansoda: 你只要格式正確的話上面幾個作法應該都可行 09/22 19:23
→ clansoda: loop最好作為最後的牌,沒牌再打 09/22 19:23
→ clansoda: 你的data是不是data.frame? 09/22 20:19
→ clansoda: 我提的方法是基築於data.table package 09/22 20:19
→ clansoda: 如果你不想用或不會用data.table 09/22 20:20
→ clansoda: 可以參考cele大的或oba大的方法 cele大的方法不用 09/22 20:20
→ clansoda: 額外的library 09/22 20:20
→ tony1331: cel大,我跑你的code,他是篩出00:00:00~02:00:00,有詳 09/22 20:21
→ tony1331: 細的說明嗎,謝謝~ 09/22 20:21
→ tony1331: cl大,不好意思,我是不會用,謝謝你! 09/22 20:22
→ celestialgod: 請google regular expression,其實只是這個的應用 09/22 20:25
→ celestialgod: 而已 09/22 20:25
→ tony1331: 好的,我馬上來google,感謝你!! 09/22 20:27
推 clansoda: regex我還是常常要在那邊試來試去的 沒辦法一次到位 09/22 20:30
→ celestialgod: 應該是不夠熟XDD 09/22 20:41
→ celestialgod: 利用regexOne把題目都做完看看 09/22 20:41
→ celestialgod: 其實多數會用到的regexp豆不難.... 09/22 20:42
→ clansoda: 真的不常用,每次要用都要查 09/22 20:43
→ celestialgod: 其實適用場域非常多,只是你要不要用而已,工作上, 09/22 20:46
→ celestialgod: 幾乎每次程式都會用到,包刮oracle sql也會用 09/22 20:46