[datatable-help] 'OR' operation with data.table

Christofer Bogaso bogaso.christofer at gmail.com
Sun Nov 17 00:00:33 CET 2013


Thanks a lot. This is working for me.

Thanks and regards,


On Sun, Nov 17, 2013 at 4:41 AM, Arunkumar Srinivasan <aragorn168b at gmail.com
> wrote:

>  How about this?
> DT[CJ(c("a", "b"), c("B", "D"))]
>
> Arun
>
> On Saturday, November 16, 2013 at 11:53 PM, Christofer Bogaso wrote:
>
> Hello all,
>
> I am a new user of data.table and really started to liking it :)
>
> I am seeking some suggestion on how I can implement 'OR'/AND' operator to
> fetch a subset of a data.table.
>
> Below is my example data.table (my actual data.table is quite big):
>
> DT = data.table(x = 1:20, y1 = rep(letters[1:4], 5), y2 =
> rep(LETTERS[1:4], each = 5))
> setkey(DT, y1, y2)
>
> > DT
>      x y1 y2
>  1:  1  a  A
>  2:  5  a  A
>  3:  9  a  B
>  4: 13  a  C
>  5: 17  a  D
>  6:  2  b  A
>  7:  6  b  B
>  8: 10  b  B
>  9: 14  b  C
> 10: 18  b  D
> 11:  3  c  A
> 12:  7  c  B
> 13: 11  c  C
> 14: 15  c  C
> 15: 19  c  D
> 16:  4  d  A
> 17:  8  d  B
> 18: 12  d  C
> 19: 16  d  D
> 20: 20  d  D
>
>
> Now I want to fetch those rows for which "y1 = a OR b  AND y2 = B OR D"
>
> with ordinary data.frame, this is straightforward to achieve, however I am
> wondering what could be the data.table way for fast computation.
>
> I would really appreciate for your help/pointer.
>
> Thanks and regards,
>
> _______________________________________________
> datatable-help mailing list
> datatable-help at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20131117/882c2c46/attachment.html>


More information about the datatable-help mailing list