You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When performing non-equi joins (<, >, <=, >=), it's important to understand how column names are assigned in the result.
575
575
576
-
- The left operand (`x` column) determines the column name in the result.
577
-
- The right operand (`i` column) contributes values but does not retain its original name.
578
-
- By default, `data.table` does not retain the `i` column used in the join condition unless explicitly requested.
576
+
- The left operand (x column) determines the column name in the result.
577
+
- The right operand (i column) contributes values but does not retain its original name.
578
+
- By default, data.table does not retain the i column used in the join condition unless explicitly requested.
579
579
580
-
In non-equi joins, the left side of the operator (e.g., `A` in `A >= B`) must be a column from `x`,
581
-
and the right side (e.g., `B`) must be a column from `i`. Non-equi join does not support arbitrary expressions. For example, `on = .(x_col >= i_col)` is valid, but `on = .(x_col >= i_col + 1)` is not.
580
+
In non-equi joins, the left side of the operator (e.g., A in A >= B) must be a column from x,
581
+
and the right side (e.g., B) must be a column from i. Non-equi join does not support arbitrary expressions. For example, on = .(x_col >= i_col) is valid, but on = .(x_col >= i_col + 1) is not.
582
582
583
583
Arbitrary comparisons can be accomplished by create temporary columns first. For example:
i <- data.table(B = c(2, 4, 5), value_i = LETTERS[1:3])
588
588
x[i, on = .(A >= B)]
589
589
```
590
-
```In data.table, when using a non-equi join condition (>=, <, etc.), the column from x is retained in the result, while the column from i is not retained unless explicitly selected.```
590
+
In data.table, when using a non-equi join condition (>=, <, etc.), the column from x is retained in the result, while the column from i is not retained unless explicitly selected.
591
591
592
592
Expected Output
593
-
A value_x value_i
593
+
A value_x value_i
594
594
1: 2 b A
595
595
2: 4 d B
596
596
3: 5 e C
@@ -610,9 +610,6 @@ Updated Output
610
610
3: 5 5 e C
611
611
4: 5 5 e C
612
612
613
-
Now, B from i is explicitly retained in the final table.
614
-
615
-
`important Consideration: nomatch = NULL in Non-Equi Joins`
616
613
If you want to exclude unmatched rows, you should use nomatch = NULL:
0 commit comments