I am trying to do a full join on two datasets where the merge by columns differ in their values and I am trying to merge data based on the closest lower value. Example dataset 1
Example dataset 2
What I want it to look like
I have tried to use fuzzy_full_join
fuzzy_full_join(gps.pts, dive.sum, by = c('num' = 'num.1'), match_fun = '>')
but get the following error
Error in which(m) : argument to 'which' is not logical



We could use
join_by()dplyr >= 1.1.0We now could do
Rolling joins
Rolling joins are a variant of inequality joins that limit the results returned from an inequality join condition. They are useful for "rolling" the closest match forward/backwards when there isn't an exact match. To construct a rolling join, wrap an inequality with
closest().closest(expr)expr must be an inequality involving one of:
>, >=, <, or <=For example,
closest(x >= y)is interpreted as: For each value in x, find the closest value in y that is less than or equal to that x value.closest()will always use the left-hand table (x) as the primary table, and the right-hand table (y) as the one to find the closest match in, regardless of how the inequality is specified. For example, closest(y$a >= x$b) will always be interpreted as closest(x$b <= y$a).See ?join_by()
data.tabledata: