Dear all, 

I am struggling with what should probably be a trivial problem. 
I have 2 seg files with the following structure:

    chr    start   end  feature.1  feature.2 
    1       1000  1200   0.5          0.001


    chr    start   end  feature.1  feature.2  
    1       1100  1400   0.7          0.004


Let's call them A and B. I want to obtain a unique file like this:


    chr    start   end     feature.1.a      feature.1.b
    1       1000    1100     0.5             NA
    1       1100    1200       0.5            0.7
    1       1200    1400     NA             0.7


If a region is covered by only A or B, then it would contain only the corresponding values and it would have NA in the other fields. Otherwise, I want to retrieve both of them. 
This looks close to what bedtools -intersect does, and indeed I am trying to use the package Bedr to solve this task, but it seems to leave out regions covered only in one file. 
Maybe GenomicRanges is another possibility.
If you have any hint on this it would be very helpful to me. 
Thank you

I managed to deal with the issue using data.table::foverlaps. I report an example from another thread.

https://www.biostars.org/p/348933/#348990

The solution needs to be adapted but essentially solves the problem.