I have a large datasets (d1)like this below:
SNP Position Chromosome
rs1 10010 1
rs2 10020 1
rs3 10030 1
rs4 10040 1
rs5 10010 2
rs6 10020 2
rs7 10030 2
rs8 10040 2
rs9 10010 3
rs10 10020 3
rs11 10030 3
rs12 10040 3
I also have a dataset(d2) like below:
SNP Position Chromosome
rsA 10015 1
rsB 10035 3
Now, i want to select a range of SNPs in d1 based on the d2(Position+-5 and the same chromosome), and write the results to txt file, the results should be like this:
SNP(d2) SNP(d1) Position(d1) Chromosome
rsA rs2 10020 1
rsA rs3 10030 1
rsB rs11 10030 3
rsB rs12 10040 3
I am new in R, can anyone please tell me how to do that in R? You kind of reply are highly appreciated.