R/difference_join.R
difference_join.Rd
Join two tables based on absolute difference between their columns
difference_join( x, y, by = NULL, max_dist = 1, mode = "inner", distance_col = NULL ) difference_inner_join(x, y, by = NULL, max_dist = 1, distance_col = NULL) difference_left_join(x, y, by = NULL, max_dist = 1, distance_col = NULL) difference_right_join(x, y, by = NULL, max_dist = 1, distance_col = NULL) difference_full_join(x, y, by = NULL, max_dist = 1, distance_col = NULL) difference_semi_join(x, y, by = NULL, max_dist = 1, distance_col = NULL) difference_anti_join(x, y, by = NULL, max_dist = 1, distance_col = NULL)
x | A tbl |
---|---|
y | A tbl |
by | Columns by which to join the two tables |
max_dist | Maximum distance to use for joining |
mode | One of "inner", "left", "right", "full" "semi", or "anti" |
distance_col | If given, will add a column with this name containing the difference between the two |
library(dplyr)#> #>#>#> #>#>#> #>head(iris)#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> 1 5.1 3.5 1.4 0.2 setosa #> 2 4.9 3.0 1.4 0.2 setosa #> 3 4.7 3.2 1.3 0.2 setosa #> 4 4.6 3.1 1.5 0.2 setosa #> 5 5.0 3.6 1.4 0.2 setosa #> 6 5.4 3.9 1.7 0.4 setosa#> Warning: `data_frame()` is deprecated as of tibble 1.1.0. #> Please use `tibble()` instead. #> This warning is displayed once every 8 hours. #> Call `lifecycle::last_warnings()` to see where this warning was generated.iris %>% difference_inner_join(sepal_lengths, max_dist = .5)#>#> Sepal.Length.x Sepal.Width Petal.Length Petal.Width Species #> 1 5.1 3.5 1.4 0.2 setosa #> 2 4.9 3.0 1.4 0.2 setosa #> 3 4.7 3.2 1.3 0.2 setosa #> 4 4.6 3.1 1.5 0.2 setosa #> 5 5.0 3.6 1.4 0.2 setosa #> 6 5.4 3.9 1.7 0.4 setosa #> 7 4.6 3.4 1.4 0.3 setosa #> 8 5.0 3.4 1.5 0.2 setosa #> 9 4.9 3.1 1.5 0.1 setosa #> 10 5.4 3.7 1.5 0.2 setosa #> 11 4.8 3.4 1.6 0.2 setosa #> 12 4.8 3.0 1.4 0.1 setosa #> 13 5.8 4.0 1.2 0.2 setosa #> 14 5.7 4.4 1.5 0.4 setosa #> 15 5.4 3.9 1.3 0.4 setosa #> 16 5.1 3.5 1.4 0.3 setosa #> 17 5.7 3.8 1.7 0.3 setosa #> 18 5.1 3.8 1.5 0.3 setosa #> 19 5.4 3.4 1.7 0.2 setosa #> 20 5.1 3.7 1.5 0.4 setosa #> 21 4.6 3.6 1.0 0.2 setosa #> 22 5.1 3.3 1.7 0.5 setosa #> 23 4.8 3.4 1.9 0.2 setosa #> 24 5.0 3.0 1.6 0.2 setosa #> 25 5.0 3.4 1.6 0.4 setosa #> 26 5.2 3.5 1.5 0.2 setosa #> 27 5.2 3.4 1.4 0.2 setosa #> 28 4.7 3.2 1.6 0.2 setosa #> 29 4.8 3.1 1.6 0.2 setosa #> 30 5.4 3.4 1.5 0.4 setosa #> 31 5.2 4.1 1.5 0.1 setosa #> 32 5.5 4.2 1.4 0.2 setosa #> 33 5.5 4.2 1.4 0.2 setosa #> 34 4.9 3.1 1.5 0.2 setosa #> 35 5.0 3.2 1.2 0.2 setosa #> 36 5.5 3.5 1.3 0.2 setosa #> 37 5.5 3.5 1.3 0.2 setosa #> 38 4.9 3.6 1.4 0.1 setosa #> 39 5.1 3.4 1.5 0.2 setosa #> 40 5.0 3.5 1.3 0.3 setosa #> 41 4.5 2.3 1.3 0.3 setosa #> 42 5.0 3.5 1.6 0.6 setosa #> 43 5.1 3.8 1.9 0.4 setosa #> 44 4.8 3.0 1.4 0.3 setosa #> 45 5.1 3.8 1.6 0.2 setosa #> 46 4.6 3.2 1.4 0.2 setosa #> 47 5.3 3.7 1.5 0.2 setosa #> 48 5.0 3.3 1.4 0.2 setosa #> 49 7.0 3.2 4.7 1.4 versicolor #> 50 6.4 3.2 4.5 1.5 versicolor #> 51 6.9 3.1 4.9 1.5 versicolor #> 52 5.5 2.3 4.0 1.3 versicolor #> 53 5.5 2.3 4.0 1.3 versicolor #> 54 6.5 2.8 4.6 1.5 versicolor #> 55 6.5 2.8 4.6 1.5 versicolor #> 56 5.7 2.8 4.5 1.3 versicolor #> 57 6.3 3.3 4.7 1.6 versicolor #> 58 4.9 2.4 3.3 1.0 versicolor #> 59 6.6 2.9 4.6 1.3 versicolor #> 60 5.2 2.7 3.9 1.4 versicolor #> 61 5.0 2.0 3.5 1.0 versicolor #> 62 5.9 3.0 4.2 1.5 versicolor #> 63 6.0 2.2 4.0 1.0 versicolor #> 64 6.1 2.9 4.7 1.4 versicolor #> 65 5.6 2.9 3.6 1.3 versicolor #> 66 6.7 3.1 4.4 1.4 versicolor #> 67 5.6 3.0 4.5 1.5 versicolor #> 68 5.8 2.7 4.1 1.0 versicolor #> 69 6.2 2.2 4.5 1.5 versicolor #> 70 5.6 2.5 3.9 1.1 versicolor #> 71 5.9 3.2 4.8 1.8 versicolor #> 72 6.1 2.8 4.0 1.3 versicolor #> 73 6.3 2.5 4.9 1.5 versicolor #> 74 6.1 2.8 4.7 1.2 versicolor #> 75 6.4 2.9 4.3 1.3 versicolor #> 76 6.6 3.0 4.4 1.4 versicolor #> 77 6.8 2.8 4.8 1.4 versicolor #> 78 6.7 3.0 5.0 1.7 versicolor #> 79 6.0 2.9 4.5 1.5 versicolor #> 80 5.7 2.6 3.5 1.0 versicolor #> 81 5.5 2.4 3.8 1.1 versicolor #> 82 5.5 2.4 3.8 1.1 versicolor #> 83 5.5 2.4 3.7 1.0 versicolor #> 84 5.5 2.4 3.7 1.0 versicolor #> 85 5.8 2.7 3.9 1.2 versicolor #> 86 6.0 2.7 5.1 1.6 versicolor #> 87 5.4 3.0 4.5 1.5 versicolor #> 88 6.0 3.4 4.5 1.6 versicolor #> 89 6.7 3.1 4.7 1.5 versicolor #> 90 6.3 2.3 4.4 1.3 versicolor #> 91 5.6 3.0 4.1 1.3 versicolor #> 92 5.5 2.5 4.0 1.3 versicolor #> 93 5.5 2.5 4.0 1.3 versicolor #> 94 5.5 2.6 4.4 1.2 versicolor #> 95 5.5 2.6 4.4 1.2 versicolor #> 96 6.1 3.0 4.6 1.4 versicolor #> 97 5.8 2.6 4.0 1.2 versicolor #> 98 5.0 2.3 3.3 1.0 versicolor #> 99 5.6 2.7 4.2 1.3 versicolor #> 100 5.7 3.0 4.2 1.2 versicolor #> 101 5.7 2.9 4.2 1.3 versicolor #> 102 6.2 2.9 4.3 1.3 versicolor #> 103 5.1 2.5 3.0 1.1 versicolor #> 104 5.7 2.8 4.1 1.3 versicolor #> 105 6.3 3.3 6.0 2.5 virginica #> 106 5.8 2.7 5.1 1.9 virginica #> 107 7.1 3.0 5.9 2.1 virginica #> 108 6.3 2.9 5.6 1.8 virginica #> 109 6.5 3.0 5.8 2.2 virginica #> 110 6.5 3.0 5.8 2.2 virginica #> 111 4.9 2.5 4.5 1.7 virginica #> 112 7.3 2.9 6.3 1.8 virginica #> 113 6.7 2.5 5.8 1.8 virginica #> 114 7.2 3.6 6.1 2.5 virginica #> 115 6.5 3.2 5.1 2.0 virginica #> 116 6.5 3.2 5.1 2.0 virginica #> 117 6.4 2.7 5.3 1.9 virginica #> 118 6.8 3.0 5.5 2.1 virginica #> 119 5.7 2.5 5.0 2.0 virginica #> 120 5.8 2.8 5.1 2.4 virginica #> 121 6.4 3.2 5.3 2.3 virginica #> 122 6.5 3.0 5.5 1.8 virginica #> 123 6.5 3.0 5.5 1.8 virginica #> 124 6.0 2.2 5.0 1.5 virginica #> 125 6.9 3.2 5.7 2.3 virginica #> 126 5.6 2.8 4.9 2.0 virginica #> 127 6.3 2.7 4.9 1.8 virginica #> 128 6.7 3.3 5.7 2.1 virginica #> 129 7.2 3.2 6.0 1.8 virginica #> 130 6.2 2.8 4.8 1.8 virginica #> 131 6.1 3.0 4.9 1.8 virginica #> 132 6.4 2.8 5.6 2.1 virginica #> 133 7.2 3.0 5.8 1.6 virginica #> 134 7.4 2.8 6.1 1.9 virginica #> 135 6.4 2.8 5.6 2.2 virginica #> 136 6.3 2.8 5.1 1.5 virginica #> 137 6.1 2.6 5.6 1.4 virginica #> 138 6.3 3.4 5.6 2.4 virginica #> 139 6.4 3.1 5.5 1.8 virginica #> 140 6.0 3.0 4.8 1.8 virginica #> 141 6.9 3.1 5.4 2.1 virginica #> 142 6.7 3.1 5.6 2.4 virginica #> 143 6.9 3.1 5.1 2.3 virginica #> 144 5.8 2.7 5.1 1.9 virginica #> 145 6.8 3.2 5.9 2.3 virginica #> 146 6.7 3.3 5.7 2.5 virginica #> 147 6.7 3.0 5.2 2.3 virginica #> 148 6.3 2.5 5.0 1.9 virginica #> 149 6.5 3.0 5.2 2.0 virginica #> 150 6.5 3.0 5.2 2.0 virginica #> 151 6.2 3.4 5.4 2.3 virginica #> 152 5.9 3.0 5.1 1.8 virginica #> Sepal.Length.y Type #> 1 5 1 #> 2 5 1 #> 3 5 1 #> 4 5 1 #> 5 5 1 #> 6 5 1 #> 7 5 1 #> 8 5 1 #> 9 5 1 #> 10 5 1 #> 11 5 1 #> 12 5 1 #> 13 6 2 #> 14 6 2 #> 15 5 1 #> 16 5 1 #> 17 6 2 #> 18 5 1 #> 19 5 1 #> 20 5 1 #> 21 5 1 #> 22 5 1 #> 23 5 1 #> 24 5 1 #> 25 5 1 #> 26 5 1 #> 27 5 1 #> 28 5 1 #> 29 5 1 #> 30 5 1 #> 31 5 1 #> 32 5 1 #> 33 6 2 #> 34 5 1 #> 35 5 1 #> 36 5 1 #> 37 6 2 #> 38 5 1 #> 39 5 1 #> 40 5 1 #> 41 5 1 #> 42 5 1 #> 43 5 1 #> 44 5 1 #> 45 5 1 #> 46 5 1 #> 47 5 1 #> 48 5 1 #> 49 7 3 #> 50 6 2 #> 51 7 3 #> 52 5 1 #> 53 6 2 #> 54 6 2 #> 55 7 3 #> 56 6 2 #> 57 6 2 #> 58 5 1 #> 59 7 3 #> 60 5 1 #> 61 5 1 #> 62 6 2 #> 63 6 2 #> 64 6 2 #> 65 6 2 #> 66 7 3 #> 67 6 2 #> 68 6 2 #> 69 6 2 #> 70 6 2 #> 71 6 2 #> 72 6 2 #> 73 6 2 #> 74 6 2 #> 75 6 2 #> 76 7 3 #> 77 7 3 #> 78 7 3 #> 79 6 2 #> 80 6 2 #> 81 5 1 #> 82 6 2 #> 83 5 1 #> 84 6 2 #> 85 6 2 #> 86 6 2 #> 87 5 1 #> 88 6 2 #> 89 7 3 #> 90 6 2 #> 91 6 2 #> 92 5 1 #> 93 6 2 #> 94 5 1 #> 95 6 2 #> 96 6 2 #> 97 6 2 #> 98 5 1 #> 99 6 2 #> 100 6 2 #> 101 6 2 #> 102 6 2 #> 103 5 1 #> 104 6 2 #> 105 6 2 #> 106 6 2 #> 107 7 3 #> 108 6 2 #> 109 6 2 #> 110 7 3 #> 111 5 1 #> 112 7 3 #> 113 7 3 #> 114 7 3 #> 115 6 2 #> 116 7 3 #> 117 6 2 #> 118 7 3 #> 119 6 2 #> 120 6 2 #> 121 6 2 #> 122 6 2 #> 123 7 3 #> 124 6 2 #> 125 7 3 #> 126 6 2 #> 127 6 2 #> 128 7 3 #> 129 7 3 #> 130 6 2 #> 131 6 2 #> 132 6 2 #> 133 7 3 #> 134 7 3 #> 135 6 2 #> 136 6 2 #> 137 6 2 #> 138 6 2 #> 139 6 2 #> 140 6 2 #> 141 7 3 #> 142 7 3 #> 143 7 3 #> 144 6 2 #> 145 7 3 #> 146 7 3 #> 147 7 3 #> 148 6 2 #> 149 6 2 #> 150 7 3 #> 151 6 2 #> 152 6 2