op <- options(digits.secs=3)

d1 = cbind(as.numeric(hengli_24v[,1]) * 20, hengli_24v)
d2 = cbind(as.numeric(hengli_480v[,1]) * 20, hengli_480v)
d3 = cbind(as.numeric(hengli_plant[,1]) * 20, hengli_plant)
d3$any = apply(d3[,3:length(names(d3))], 1, any)


# merge based on nearest 100ms
merged = merge(merge(
  d1, d2, by=1, suffixes=c("_24v", "_480v"), all.x = TRUE
), d3, by=1, all.x = TRUE)

library(tidyr)
merged = merged %>% fill(names(merged), .direction = 'up')

library(dplyr)
merged$group = cumsum(merged$seitenteil_links_und_rechts_oeffnen & !lag(merged)$any)

s = split(merged, merged$group)[-1]
