5
$\begingroup$

For a given keyless dataset, I can query to return the rows whose columns contain a specific value. For example:

ds = Dataset[{{"a", "b"}, {"c", "d"}, {"e", "f"}, {"g", "h"}}]
Query[Select[#[[2]] == "f" &]]@ds

returns the dataset {e,f}.

But, in this simple example, I would like to test:

 Query[#[[2]]=="f"||#[[2]]="g"&]]@ds

How can I perform this operation without writing out every value of interest. For example, I want check if #[[2]] contains any value from the list"check":

check={"f","g"}

ds[GroupBy[#[[2]]&][check] changes the dataset structure. I just want to remove rows from the original dataset.

$\endgroup$
4
  • 4
    $\begingroup$ You could do Query[Select[MemberQ[check, #[[2]]] &]]@ds, for example. $\endgroup$ Jun 18, 2015 at 14:04
  • $\begingroup$ Slick--I had been trying MemberQ but not implementing it correctly. Please add as an answer so that I can give credit. $\endgroup$
    – Docuemada
    Jun 18, 2015 at 14:08
  • $\begingroup$ @LeonidShifrin may not see your comment. You can "ping" a user by adding the @ sign before their name, as I did at the beginning of this message. In case he was not interested in converting his comment into an answer, though, I'd urge you to do that yourself (self-answering is encouraged on Stack Exchange) so your question will have a full answer and will be more appealing to future users who encounter similar problems. $\endgroup$
    – MarcoB
    Jun 19, 2015 at 2:57
  • $\begingroup$ Ok, posted an answer as requested. $\endgroup$ Jun 19, 2015 at 9:33

1 Answer 1

3
$\begingroup$

Here is one way:

Query[Select[MemberQ[check, #[[2]]] &]] @ ds
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.