# Dataset, use list as header

I have a dataset with a header for row and column which consists of binaries, e.g.:

cols = ToString /@ IntegerDigits[Range[3], 2, 3]
rows = ToString /@ IntegerDigits[Range[3], 2, 3]
tbl = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}



Now I would like to extract parts of the matrix by a pattern, e.g. row: {1,0,_} and column: {__,0,0} for the full binary this works:

data[ToString[{0, 0, 0}]][ToString[{1, 0, 0}]]


But now I would like to extract patterns like _,0,0 How can this be done? Is their a way to use a list as header for row and column instead of strings?

thanks

If you must use strings instead of the lists, I would say it is a bit awkward. But it is possible.

data = Dataset[AssociationThread[rows, tbl]][All,
matchedrows =
StringMatchQ[#, RegularExpression["{0, 0, \\d}"]] &]
matchedcols =
StringMatchQ[#, RegularExpression["{\\d, 0, 1}"]] &]
data[matchedrows, matchedcols]


Note that I chose selections that give a non-empty set of results, that these selections are based on regular expressions, and that we need to notice the presence of spaces in the string representations of the lists.

• thanks @Alan. Actually I must not use strings, but I when I use lists it gives me a strange representation of the dataset: cols = IntegerDigits[Range[3], 2, 3] rows = IntegerDigits[Range[3], 2, 3] tbl = {{1, 0, 1}, {0, 1, 0}, {1, 1, 0}} data = Dataset[AssociationThread[rows, tbl]][All, AssociationThread[cols, Range[Length[cols]]]] Jul 15 '17 at 5:59

You may use KeySelect and StringMatchQ.

With data as in OP with string keys.

data


Then

data[
KeySelect[StringMatchQ[RegularExpression["{0, 1, \\d}"]]],
KeySelect[StringMatchQ[RegularExpression["{\\d, 1, \\d}"]]]]


Hope this helps.