Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. library(data.table)
  2. library(chron)
  3. setDT(df1)[, .(timeinterval = paste(time1[1], time2[.N]), timecount = sum(timecount)),
  4. by = .(grp=cumsum(shift((times(shift(time1, type = "lead", fill = time1[.N])) -
  5. times(time2)) >= 0.05, fill = TRUE)) )][, grp := NULL][]
  6. # timeinterval timecount
  7. #1: 00:00:00 02:59:59 6
  8. #2: 08:00:00 09:59:59 4
  9. #3: 14:00:00 14:59:59 2
  10. #4: 17:00:00 17:59:59 2
  11. #5: 21:00:00 23:59:59 6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement