0
$\begingroup$

I have a list of triples and a matrix. I want to use the triples as header for row and column in a dataset so that it looks like this:

enter image description here

But with the code I have so far it makes the wrong associations:

header = IntegerDigits[Range[3], 2, 3];
tbl = {{1, 0, 1}, {0, 1, 0}, {1, 1, 0}};

data = 
  Dataset[AssociationThread[header, tbl]]
    [All, AssociationThread[header, Range[Length[header]]]]

Any ideas on how to solve this?

$\endgroup$
  • $\begingroup$ From your previous question you should know that you have to use header = ToString /@ IntegerDigits[Range[3], 2, 3] $\endgroup$ – eldo Jul 15 '17 at 8:52
  • $\begingroup$ @eldo, yes, but it will create a string as header obviously. What if I want the header as lists? $\endgroup$ – Wafram Jul 15 '17 at 9:02
1
$\begingroup$

The following produces a dataset that displays like the one you show in your question. It may not have the behavior you want, but since you didn't make it clear what that behavior is, I can't do more.

header = IntegerDigits[Range[3], 2, 3];
tbl = {{1, 0, 1}, {0, 1, 0}, {1, 1, 0}};
MapThread[
  Association@*Prepend,
  {MapThread[Rule, {ConstantArray[ToString /@ header, Length @ header], tbl}, 2],
   " " -> # & /@ header}] // Dataset

dataset

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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