.()
and J()
as the function
wrapping the i
argument of data.table
are simply replaced by list()
because [.data.table
does some programming on the language of the i
and j
arguments to optimize how things are done internally. It can be thought of as a alias for list
The reason they are included is to allow save time and effort (3 key strokes!)
If I wanted to select key values 'a'
or 'c'
from the first column of a key I could do
DT[.(c('a','c'))]
# or
DT[J(c('a','c'))]
# or
DT[list(c('a','c'))]
If I wanted A='a' or 'c'
and B = 'd'
then I would could use
DT[.(c('a','c'),'d')]
If I wanted A = 'a' or 'c' and B = 'd' or 'e'
then I would use CJ
(or expand.grid
) to create all combinations
DT[CJ(c('a','c'),c('d','e'))]
The help for J
,SJ
and CJ
is quite well written! See also the vignette Keys and fast binary search based subset.