One obvious way is to take tail(x$V2, -1L) - head(x$V3, -1L)
and get the start and end indices corresponding to the maximum consecutive 1
s. But I'll skip it here (and leave it to others) as I'd like to show how this can be done with the help of IRanges
package:
require(data.table)
require(IRanges) ## Bioconductor package
x.ir = reduce(IRanges(x$V2, x$V3))
max.idx = which.max(width(x.ir))
ans = data.table(out.name = "DOG.1",
in = start(x.ir)[max.idx],
out = end(x.ir)[max.idx])
# out.name bla out
# 1: DOG.1 313 324