我試圖總結兩個變量之間的時間差,並找到列表的長度。根據特定間隔的切點
我的數據集看起來像這樣。我想要得到他們的差距低於6點的步驟數。
Group Time1 Gap
A 11:00:00 AM
A 11:04:00 AM 4:00
A 11:06:00 AM 2:00
A 11:08:00 AM 2:00
A 11:12:00 AM 4:00
A 11:19:00 AM 7:00
A 11:26:00 AM 7:00
A 11:28:00 AM 2:00
A 11:30:00 AM 2:00
A 11:32:00 AM 2:00
A 11:34:00 AM 2:00
A 11:36:00 AM 2:00
最終結果應該是這樣;
Group Gap Step
A 12:00 4
如果間隔大於6:00,我不想繼續計算其他步驟。
我用過濾器選項「...%>%filter(gap < 8:00)%>%...」但它沒有工作。我知道切點將把這個列表分成兩個獨立的部分。
樣品DF:
structure(list(Group = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L), .Label = "A", class = "factor"), Time1 = structure(1:12, .Label = c("11:00:00 AM",
"11:04:00 AM", "11:06:00 AM", "11:08:00 AM", "11:12:00 AM", "11:19:00 AM",
"11:26:00 AM", "11:28:00 AM", "11:30:00 AM", "11:32:00 AM", "11:34:00 AM",
"11:36:00 AM"), class = "factor"), Gap = structure(c(1L, 3L,
2L, 2L, 3L, 4L, 4L, 2L, 2L, 2L, 2L, 2L), .Label = c("", "2:00",
"4:00", "7:00"), class = "factor")), .Names = c("Group", "Time1",
"Gap"), class = "data.frame", row.names = c(NA, -12L))
我還需要找到總時間間隔的時間在這5個步驟。在我的示例df中,總時隙等於第5步差距值! – eabanoz