我試圖評估行的時間元素以創建TRUE/FALSE列。例如:評估行元素之間的時間
datetime
10/10/15 0:45
10/1/15 0:45
10/10/15 0:30
10/1/15 0:30
10/10/15 0:15
10/1/15 0:15
10/10/15 0:00
10/1/15 0:00
10/10/15 10:45
10/10/15 1:45
10/10/15 10:30
10/10/15 1:30
10/10/15 10:15
10/10/15 1:15
10/10/15 11:45
10/10/15 11:30
10/10/15 11:15
10/10/15 11:00
10/10/15 12:45
10/10/15 12:30
10/10/15 12:15
10/10/15 12:00
10/10/15 13:45
10/10/15 13:30
10/10/15 13:15
10/10/15 14:45
10/10/15 14:30
10/10/15 14:15
10/10/15 14:00
10/10/15 15:45
10/10/15 15:30
10/10/15 15:15
10/10/15 15:00
10/10/15 16:45
10/10/15 16:30
10/10/15 16:15
10/10/15 17:45
10/10/15 17:30
10/10/15 17:15
10/10/15 17:00
10/10/15 18:45
10/10/15 18:30
10/10/15 18:15
10/10/15 18:00
10/10/15 19:45
10/10/15 19:30
10/10/15 19:15
10/10/15 20:45
10/10/15 2:45
10/10/15 20:30
10/10/15 2:30
10/10/15 20:15
10/10/15 2:15
10/10/15 20:00
10/10/15 2:00
10/10/15 21:45
10/10/15 21:30
10/10/15 21:15
10/10/15 21:00
10/10/15 22:45
10/10/15 22:30
10/10/15 22:15
10/10/15 23:45
10/10/15 23:30
10/10/15 23:15
10/10/15 23:00
10/10/15 3:45
10/10/15 3:30
10/10/15 3:15
10/10/15 3:00
10/10/15 4:45
10/10/15 4:30
10/10/15 4:15
10/10/15 5:45
10/10/15 5:30
10/10/15 5:15
10/10/15 5:00
10/10/15 6:45
10/10/15 6:30
10/10/15 6:15
10/10/15 6:00
10/10/15 7:45
10/10/15 7:30
10/10/15 7:15
10/10/15 8:45
10/10/15 8:30
10/10/15 8:15
10/10/15 8:00
10/10/15 9:45
10/10/15 9:30
10/10/15 9:15
10/10/15 9:00
10/1/15 10:45
10/1/15 1:45
10/1/15 10:30
10/1/15 1:30
10/1/15 10:15
10/1/15 1:15
10/1/15 10:00
10/11/15 10:45
假設我想要一個變量,使得:
v1 = TRUE if 7:45<time(datetime)<8:15
AND v1 = TRUE if 23:45<time(datetime)<0:15 (next day)
ELSE = FALSE
從本質上講,我正在尋找類似於dplyr::mutate(between, a, b)
做一些事情,但瞭解的時間。
我的數據存儲如下:
$ datetime : POSIXct, format: "2015-10-10 00:45:00" "2015-10-01 00:45:00" "2015-10-10 00:30:00" "2015-10-01 00:30:00" ...
$ year : int 2015 2015 2015 2015 2015 2015 2015 2015 2015 2015 ...
$ month : int 10 10 10 10 10 10 10 10 10 10 ...
$ day : int 10 1 10 1 10 1 10 1 10 10 ...
$ minute : int 45 45 30 30 14 14 0 0 44 44 ...
我應該說,我知道如何從第一原理那裏有很多的中間步驟。我正在尋找更優雅,緊湊的解決方案。 –
請給出一個可重複的例子或使用'dput' – statquant