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
Always use `on`with indices to avoid errors. Keys establish permanent implicit matching, while indices require explicit direction for each operation.
84
+
For join-like operations such as `DT[.(values)]` on an indexed table, the `on=` argument is essential to specify the join column(s). `setindex` does not establish the implicit matching that setkey does; thus, this `explicit` direction is needed.
85
85
86
-
#### **Hierarchy of Lookup Operations**
86
+
#### Hierarchy of Lookup Operations
87
87
88
88
When `on` is specified, `data.table` uses this lookup order:
89
89
90
90
- Existing keys matching `on` columns
91
91
92
92
- Pre-built secondary indices matching `on` columns
93
93
94
-
- Temporary auto-generated index (if none exist)
95
-
96
-
**Example**: Error When Omitting on with Indices
97
-
98
-
```{r}
99
-
DT <- data.table(a = c(TRUE, FALSE), b = 1:2)
100
-
setindex(DT, a)
101
-
# DT[.(TRUE)] # Uncommenting this line causes: Error - must specify 'on'
102
-
```
103
-
104
-
- Use `DT[.(value)]` when the table is keyed by the relevant column(s).
105
-
106
-
- Use `DT[.(value), on = "col"]` when using secondary indices or when no key is set.
94
+
- Auto-generated secondary index (created if none exist; its optimized ordering is used internally for efficient joins)
0 commit comments