I am looking to flag rows in my df that have overlapping ranges (looking to create the Overlap Column) based a range of numeric variables (Min,Max), which I could transform into integer if necessary:
Class Min Max
A 100 200
A 120 205
A 210 310
A 500 630
A 510 530
A 705 800
Transform into:
Class Min Max Overlap
A 100 200 1
A 120 205 1
A 210 310 0
A 500 630 1
A 510 530 1
A 705 800 0
I have tried IRanges without much success - any ideas?
overlap = [ (minVal > any other min) AND ( minVal < maxVal ) ] OR [ (maxVal < any other max) AND ( maxVal > minVal ) ]
Right?IRanges
, it seems you just needcountOverlaps(IRanges(dat$Min, dat$Max)) - 1