Hi everyone,

I have two unequal data sets.

    A data set
    V1     V2          V3
    6	42721754	42721769
    6	42721757	42721772
    6	42721760	42721775
    6	42721763	42721778
    6	42721766	42721781
    6	42721769	42721784
    6	42721772	42721787
    6	42721775	42721790

    B data set
    V2            	AF
    42721757	0.003067485
    42721760	0.006134969
    42721763	0.006134969
    42721766	0.003067485
    42721769	0.006134969
    42721772	0.006134969
    42721775	0.003067485
    42721778	0.006134969
    42721781	0.003067485
    42721784	0.003067485
    42721787	0.009202454
    42721790	0.009202454

I want to check if  the value of `V2` in `B data set`  falls between the values of `V2` and `V3` of `A data set`. And when its true, I want value of `AF` in `B data set` to be added as a new column in `A dataset`. 
There are two important points.
1. `B data set` is 80 rows while `A data set` is 6000 rows.
2. value of `V2` in `B` may be repeated,  which shouldn't get thrown out in final output.

an urgent help with be appreciated.

Thanks,

Using **R** *data.table*:

    library(data.table)
    
    # example data
    A <- fread(text = "
    V1     V2          V3
    6   42721754    42721769
    6   42721757    42721772
    6   42721760    42721775
    6   42721763    42721778
    6   42721766    42721781
    6   42721769    42721784
    6   42721772    42721787
    6   42721775    42721790")
    
    B <- fread(text = "
    V2              AF
    42721757    0.003067485
    42721760    0.006134969
    42721763    0.006134969
    42721766    0.003067485
    42721769    0.006134969
    42721772    0.006134969
    42721775    0.003067485
    42721778    0.006134969
    42721781    0.003067485
    42721784    0.003067485
    42721787    0.009202454
    42721790    0.009202454")
    
    
    # set the same keys for both A and B, start and end positions.
    # If we have multiple chromosomes, we need to include chrom as key, too.
    setDT(A, key = c("V2", "V3"))
    setDT(B)
    B <- B[, .(V2, V3 = V2, AF)]
    setkeyv(B, c("V2", "V3"))
    
    # merge with overlap, check the "type" argument for merge types, see ?foverlaps
    res <- foverlaps(B, A)
    head(res)
    #    V1       V2       V3     i.V2     i.V3          AF
    # 1:  6 42721754 42721769 42721757 42721757 0.003067485
    # 2:  6 42721757 42721772 42721757 42721757 0.003067485
    # 3:  6 42721754 42721769 42721760 42721760 0.006134969
    # 4:  6 42721757 42721772 42721760 42721760 0.006134969
    # 5:  6 42721760 42721775 42721760 42721760 0.006134969
    # 6:  6 42721754 42721769 42721763 42721763 0.006134969