<div dir="ltr">Hello all,<div><br></div><div>I am a new user of data.table and really started to liking it :)</div><div><br></div><div>I am seeking some suggestion on how I can implement 'OR'/AND' operator to fetch a subset of a data.table.</div>
<div><br></div><div>Below is my example data.table (my actual data.table is quite big):</div><div><br></div><div><div>DT = data.table(x = 1:20, y1 = rep(letters[1:4], 5), y2 = rep(LETTERS[1:4], each = 5))</div><div>setkey(DT, y1, y2)</div>
</div><div><br></div><div><div>> DT</div><div> x y1 y2</div><div> 1: 1 a A</div><div> 2: 5 a A</div><div> 3: 9 a B</div><div> 4: 13 a C</div><div> 5: 17 a D</div><div> 6: 2 b A</div><div> 7: 6 b B</div>
<div> 8: 10 b B</div><div> 9: 14 b C</div><div>10: 18 b D</div><div>11: 3 c A</div><div>12: 7 c B</div><div>13: 11 c C</div><div>14: 15 c C</div><div>15: 19 c D</div><div>16: 4 d A</div><div>17: 8 d B</div>
<div>18: 12 d C</div><div>19: 16 d D</div><div>20: 20 d D</div></div><div><br></div><div><br></div><div>Now I want to fetch those rows for which "y1 = a OR b AND y2 = B OR D"</div><div><br></div><div>with ordinary data.frame, this is straightforward to achieve, however I am wondering what could be the data.table way for fast computation.</div>
<div><br></div><div>I would really appreciate for your help/pointer.</div><div><br></div><div>Thanks and regards,</div><div><br></div></div>