我有以下数据:
df <- data.frame(index = 1:85,
times = c(seq(as.POSIXct("2020-10-03 21:31:00 UTC"),
as.POSIXct("2020-10-03 22:25:00 UTC")
"min"),
seq(as.POSIXct("2020-11-03 10:10:00 UTC"),
as.POSIXct("2020-11-03 10:39:00 UTC"),
"min")
))
如果我们看第55行和第56行,时间上有一个明显的鸿沟:
> df[55:56, ]
index times
55 55 2020-10-03 22:25:00
56 56 2020-11-03 10:10:00
我想根据拆分添加第三个分类列split
,
e、 g.第df$split[55, ] = A
行和第df$split[56, ] = B
行
逻辑式
If time gap between rows is greater than 5 mins start new category for subsequent rows until the next instance where time gap > 5 mins.
谢谢