I'm trying to learn data.table
package in R
. I have a data table named DT1
and a data frame DF1
, and I'd like to subset some instances according to a logical condition (disjunction). This is my code for now:
DF1[DF1$c1==0 | DF1$c2==1,] #the data.frame way with the data.frame DF1
DT1[DT1$c1==0 | DT1$c2==1,] #the data.frame way with the data.table DT1
On page 5 of "Introduction to the data.table package in R", the author gives an example of something similar but with a conjuction (replace |
by &
in the second line above) and remarks that's a bad use of data.table
package. He suggests todo it this way instead:
setkey(DT1,c1,c2)
DT1[J(0,1)]
So, my question is: How can I write the disjunction condition with the data.table
package syntax? Is it a misuse my second line DT1[DT1$c1==0 | DT1$c2==1,]
? Is there an equivalent to the J
but for disjunction?