0
$\begingroup$

I have a list in the form

join = {{3, {-5, 4, 4}}, {6, {2, -1, -1}}, {7, {-105, 32, 
104}}, {8, {-1, 1, 
2}}, {8, {18, -12, -16}}, {9, {217, -52, -216}}, {10, {-171, 130, 
141}}, {10, {4, -3, -3}}}

I've done the following:

len = Length[DeleteDuplicates[First[Transpose[join]]]]

TableForm[Table[DeleteDuplicates@Flatten[GatherBy[join, First][[i]],1], {i,1,len}],TableDepth->2]

to get the output grouped by the first element (the single number, i.e. 3, 6, 7, 8 ,9, 10) and displayed as a TableForm.

The three-element sublists contain either one or two negative numbers. I would like to have the TableForm arranged so that in the second column there will be only those containing one negative number, and in the third column only those with two negative numbers. How can I do that?

$\endgroup$
  • 1
    $\begingroup$ Did you look at Dataset? This provides quite some options on what you might be looking for. $\endgroup$ – Mockup Dungeon Aug 5 '16 at 16:36
  • $\begingroup$ please test your code. There are mistakes in the line with TableForm[... $\endgroup$ – Conor Cosnett Aug 5 '16 at 18:29
  • $\begingroup$ @MockupDungeon I don't see how I could use Dataset. @JohnConorCosnett Sorry, I lost one bracket; it's corrected now. $\endgroup$ – corey979 Aug 5 '16 at 18:45
1
$\begingroup$
join = {{3, {-5, 4, 4}}, {6, {2, -1, -1}}, {7, {-105, 32, 
     104}}, {8, {-1, 1, 
     2}}, {8, {18, -12, -16}}, {9, {217, -52, -216}}, {10, {-171, 130,
      141}}, {10, {4, -3, -3}}};
table = {#, {}, {}} & /@ Union[First /@ join];
AppendTo[table[[#1 /. 
       Thread[Union[First /@ join] -> Range@Length@table], 
      Total@Map[Boole@*Negative, #2] + 1]], #2] & @@@ join;
table // TableForm

Mathematica graphics

$\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.