Skip to content

Commit f338567

Browse files
simplify
1 parent 2cfde2f commit f338567

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

vignettes/datatable-secondary-indices-and-auto-indexing.Rmd

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,21 @@ Secondary indices are similar to `keys` in *data.table*, except for two major di
6767
While both **keys** and **indices** enable fast binary search subsetting, they differ significantly in usage:
6868

6969
**Keyed subsetting** (implicit column matching)
70+
7071
```{r}
7172
DT = data.table(a = c(TRUE, FALSE), b = 1:2)
72-
setkey(DT, a) # Set key
73-
DT[.(TRUE)] # No 'on' needed - key is used
73+
setkey(DT, a) # Set key, reordering DT
74+
DT[.(TRUE)] # 'on' is optional; if omitted, the key is used
7475
```
7576

7677
**Indexed subsetting** (explicit column specification)
7778

7879
```{r}
7980
DT = data.table(a = c(TRUE, FALSE), b = 1:2)
8081
setindex(DT, a) # Set index only (no reorder)
81-
DT[.(TRUE), on = "a"] # Must specify 'on'
82+
DT[.(TRUE), on = "a"] # 'on' is required
8283
```
8384

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-
8685
#### Hierarchy of Lookup Operations
8786

8887
When `on` is specified, `data.table` uses this lookup order:

0 commit comments

Comments
 (0)