I would like to merge/combine two files, so that if an entry in column B of my first file falls into the range of columns B and C in my second file, the output will contain all of the information contained in both files.
Like this:
file 1
A B
rs10 23353
rs100 10000
rs234 54440
file 2
A B C
E235 20000 30000
E255 50000 60000
where, because 23353 falls between 20000 and 30000, and 54440 falls between 50000 and 60000 the output file would look like this:
rs 23353 E235 20000 30000
rs234 54440 E255 50000 60000
and rs100 would be removed (from the output file) because it does not fall within a range of any row in file 2.
any suggestions?
Thank you!
UPDATE: This question was more complicated than indicated here. The solution can be found here: Merge by Range in R – Applying Loops, and is delivered by using the
GenomicRangespackage in Bioconductor. Very useful package!