2
$\begingroup$

I have a list of 4 dim points, given by

list={{0, 1/100, 6, 1/3}, {0, 1/100, 5, 1/3}, {0, 1/100, 6, 2/3}, {0, 1/ 100, 5, 2/3}, {0, 1/100, 6, 1}, {0, 1/100, 5, 1}, {1/2, 0.0132789, 6, 1/3}, {1/2, 0.00603171, 8, 1/3}, {1/2, 0.0133361, 6, 2/3}, {1/2, 0.0059745, 8, 2/3}, {1/2, 0.0133552, 6, 1}, {1/2, 0.00595543, 8, 1}, {1, 0.0148608, 6, 1/3}, {1, 0.00444984, 8, 1/3}, {1, 0.0149013, 6, 2/3}, {1, 0.00440938, 8, 2/3}, {1, 0.0149147, 6, 1}, {1, 0.0043959, 8, 1}, {3/2, 0.0160638, 6, 1/3}, {3/2, 0.0032469, 8, 1/ 3}, {3/2, 0.0160968, 6, 2/3}, {3/2, 0.00321387, 8, 2/3}, {3/2, 0.0161078, 6, 1}, {3/2, 0.00320286, 8, 1}}

I would like to gather the elements of the list using two conditions and then create a ListPlot of them. So the first two elements of each point should be the x y coordinates and the last two should be the conditions. The first condition should check if the thrid element is equal 6 and the second codition should group elements for 1/3, 2/3 and 1. I tried

GatherBy[list, {#[[3]] == 6, Last} &][[All, All, {1, 2}]]

but it takes into account only the first condition, giving me 2 lists of points. I wanted to have 6 lists of points in this example. Any ideas?

$\endgroup$
2
  • $\begingroup$ It is not very clear what you are asking for and also you are using plotPointsX in place of list or some processed version of list? $\endgroup$
    – gpap
    Commented Mar 3, 2014 at 10:22
  • $\begingroup$ Thanks, I corrected the misunderstanding. $\endgroup$
    – wlq
    Commented Mar 3, 2014 at 10:27

1 Answer 1

6
$\begingroup$

I think this is what you're asking for - question is a bit unclear:

Flatten[GatherBy[#, Last] & /@ GatherBy[list, #[[3]] == 6 &], 1]

As noted below, you can also use :

Join @@ GatherBy[list, {#[[3]] == 6 &, Last}]

But note the change in the pure-function ampersand position!

$\endgroup$
3
  • $\begingroup$ Thanks! This does exactly what I need. Thank you! $\endgroup$
    – wlq
    Commented Mar 3, 2014 at 10:27
  • 2
    $\begingroup$ You can gather into nested sublists using GatherBy[list, {#[[3]] == 6 &, Last}] $\endgroup$ Commented Mar 3, 2014 at 10:31
  • $\begingroup$ @SimonWoods: That was my first though, but produces completely different result from what OP appears to want. However a join should do the trick... $\endgroup$
    – ciao
    Commented Mar 3, 2014 at 10:35

Your Answer

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

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