Match Value and Interval via overlaps

You can try fuzzyjoin :

fuzzyjoin::fuzzy_left_join(test, test_2, 
                           by = c('amount' = 'top', 'amount' = 'bottom'), 
                           match_fun = list(`<=`, `>=`))

#   id amount interval bottom top
#1   1     19        1      0  24
#2   1     21        1      0  24
#3   1     39        2     25  49
#4   1     45        2     25  49
#5   1     62        3     50  74
#6   1     71        3     50  74
#7   1    100        5    100 124
#8   1    121        5    100 124
#9   1    130        6    125 149
#10  1    160        7    150 174
#11  1    180        8    175 199
#12  1    210        9    200 224
#13  1    240       NA     NA  NA

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top