4

I have a general form for a data.table query where I can subset my data to only look at values that match the %like% statement, it looks like

DT[Var %like% "x|y|z", .N,]

And for the general operators for excluding values

i = x != "somevalue",

How can I combine these to ignore values that sound %like% some value and only return a set that don't match these requests.

The context here is a large database of customer data and trying to remove unwanted data so this list is much smaller than the list I am interested in.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
digdeep
  • 624
  • 2
  • 10
  • 21
  • Could you show your definition for `%like%`? – Frank Oct 03 '13 at 02:10
  • 1
    In R, you can generally build compound conditions in the usual ways, like `(cond1) & (!cond2)`; and this also works in `i`... – Frank Oct 03 '13 at 02:12
  • I've removed the actual char values but it looks like this `DT[Var != %like% "valuex|orthis|orthistoo", .N,]` – digdeep Oct 03 '13 at 02:18
  • 1
    Oh, sorry, I didn't realize that %like% was defined in the data.table package. I think you are looking for `DT[!(var %like% 'expr')]`? – Frank Oct 03 '13 at 02:21
  • Cheers @Frank Thanks! that did the trick. Should look like `DT[!(Var %like% "valuex|orthis|orthistoo"), .N,]` – digdeep Oct 03 '13 at 02:24
  • Great! I guess I'll write that as an answer. On the site, it's preferred that "duplicate" questions be linked together, but the closest I could find is this: http://stackoverflow.com/q/9852832/1191259 – Frank Oct 03 '13 at 02:28

1 Answers1

12

I think you are looking for

DT[!(var %like% 'expr')]

Information on other logical operators can be found on the same help page; type ?`!` in the console to open it.

Frank
  • 66,179
  • 8
  • 96
  • 180