File tree Expand file tree Collapse file tree 1 file changed +9
-12
lines changed
Expand file tree Collapse file tree 1 file changed +9
-12
lines changed Original file line number Diff line number Diff line change @@ -371,21 +371,18 @@ A short example:
371371```{r}
372372DT = data.table(a = 1:3)
373373
374- # Create three variables using the different methods
375- x_ref = DT$a # 1. By reference with $
376- y_cpy = DT[, a] # 2. By copy with []
377- z_cpy = copy(DT$a) # 3. Forced copy with copy()
374+ # three ways to get the column
375+ x_ref = DT$a # may be a reference
376+ y_cpy = DT[, a] # always a copy
377+ z_cpy = copy(DT$a) # forced copy
378378
379- # Now, modify the original data.table by reference
379+ # modify DT by reference
380380DT[, a := a + 10L]
381381
382- # Check the variables:
383- x_ref
384- #> [1] 11 12 13
385- y_cpy
386- #> [1] 1 2 3
387- z_cpy
388- #> [1] 1 2 3
382+ # observe results
383+ x_ref # may show 11 12 13
384+ y_cpy # 1 2 3
385+ z_cpy # 1 2 3
389386```
390387
391388To select a single column as a vector, remember:
You can’t perform that action at this time.
0 commit comments