# Select specific rows of a dataset

I am struggling with extracting specific rows from a dataset.

dataset =
Dataset[{<|"a" -> 1, "b" -> "x", "c" -> {1}|>, <|"a" -> 2,
"b" -> "y", "c" -> {2, 3}|>, <|"a" -> 3, "b" -> "z",
"c" -> {3}|>, <|"a" -> 4, "b" -> "x", "c" -> {4, 5}|>, <|"a" -> 5,
"b" -> "y", "c" -> {5, 6, 7}|>, <|"a" -> 6, "b" -> "z",
"c" -> {}|>}]


I would like to get a new dataset consisting only of examples that have a specific number in column "a" (for example {2,4,5})

I can retrieve one specific row by using the following: Select[dataset, #a == 2 &] :

But I don't know how to do that for a list with the given numbers. I tried the following which gave me an empty dataset:

Select[dataset, #a == {2, 4, 5} &]

Thank you very much for your help.

Query[Select[MemberQ[{2, 4, 5}, #a] &]]@dataset


You can also use

dataset[Select[MatchQ[#a, 2 | 4 | 5] &]]


Select[MatchQ[#a, 2 | 4 | 5] &] @ dataset


Cases[KeyValuePattern["a" -> 2 | 4 | 5]]@dataset


The above answers are excellent, and complete, but when prototyping code, I often find the array indexing with datasets to be useful and sometimes a bit easier to type. Like so:

dataset[[{2,4,5}]]


Also:

Position[dataset[[;;,1]],2|4|5]


extracts the row positions which meet your criteria above,

And:

dataset[[Flatten@Position[dataset[[;;,1]],2|4|5]]]


accomplishes the same as the above answers, in a way which somehow makes more sense to me.

Just my 0.02 - I should mention I have no idea how this handles column indexing for datasets, which is probably quite important to you. My data tends to be very regular, so indexing by column number is usually sufficient.