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
Copy file name to clipboardExpand all lines: vignettes/datatable-intro.Rmd
+17-17Lines changed: 17 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -261,35 +261,35 @@ setkeyv(flights, "origin")
261
261
```
262
262
263
263
***Key-based subsetting: `dt["d"]`**
264
-
265
-
This performs a right join on the key column `x`, resulting in a row with `d` and `NA` for columns not found.
266
264
267
-
```r
265
+
This performs a right join on the key column `x`, resulting in a row with `d` and `NA` for columns not found. When using `setkeyv`, the table is sorted by the specified keys and an internal index is created, enabling binary search for efficient subsetting.
266
+
267
+
```r
268
268
flights["XYZ"]
269
-
# Returns:
270
-
# origin year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time arr_delay carrier flight tailnum ...
271
-
# 1: XYZ NA NA NA NA NA NA NA NA NA NA NA NA ...
272
-
```
269
+
# Returns:
270
+
# origin year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time arr_delay carrier flight tailnum ...
271
+
# 1: XYZ NA NA NA NA NA NA NA NA NA NA NA NA ...
272
+
```
273
273
274
274
***Logical subsetting: `dt[x == "d"]`**
275
275
276
276
This performs a standard subset operation that does not find any matching rows and thus returns an empty `data.table`.
277
277
278
-
```r
279
-
flights[origin=="XYZ"]
280
-
# Returns:
281
-
# Empty data.table (0 rows and 19 cols): year,month,day,dep_time,sched_dep_time,dep_delay,arr_time,sched_arr_time,arr_delay,...
282
-
```
278
+
```r
279
+
flights[origin=="XYZ"]
280
+
# Returns:
281
+
# Empty data.table (0 rows and 19 cols): year,month,day,dep_time,sched_dep_time,dep_delay,arr_time,sched_arr_time,arr_delay,...
282
+
```
283
283
284
284
***Exact match using `nomatch=NULL`**
285
285
286
286
For exact matches without `NA` for non-existing elements, use `nomatch=NULL`:
287
287
288
-
```r
289
-
flights["XYZ", nomatch=NULL]
290
-
# Returns:
291
-
# Empty data.table (0 rows and 19 cols): year,month,day,dep_time,sched_dep_time,dep_delay,arr_time,sched_arr_time,arr_delay,...
292
-
```
288
+
```r
289
+
flights["XYZ", nomatch=NULL]
290
+
# Returns:
291
+
# Empty data.table (0 rows and 19 cols): year,month,day,dep_time,sched_dep_time,dep_delay,arr_time,sched_arr_time,arr_delay,...
292
+
```
293
293
294
294
Understanding these behaviors can help prevent confusion when dealing with non-existing elements in your data.
0 commit comments