1
$\begingroup$

Consider the data

data = {{x1,y1,z1},{x2,y2,z2},{x3,y3,z3},{x4,y4,z4},{x5,y5,z5},{x6,y6,z6},...}

with N rows.

It can be divided into N/6 sets of 6 rows. I want to select a subdata obtained from the sets satisfying some specific requirement for 3rd rows of the sets, say data[[3+6*i]][[2]]>10.

Example:

data = {{1,2,3},{1,9,6},{1,12,6},{1,5,6},{1,6,3},{1,5,5},{3,5,6},{1,10,6},{1,8,6},{1,4,6},{1,0,4},{1,3,6}}

The data contains 2 sets of 6 rows. In the first set we have data[[3]][[2]]>10, in the second set we have data[[9]][[2]]<10, and therefore after imposing the criterion data[[3 +6*i]][[2]]>10 we obtain

subdata = {{1,2,3},{1,9,6},{1,12,6},{1,5,6},{1,6,3},{1,5,5}}
$\endgroup$
  • $\begingroup$ What is the question? You seem to have obtained what you want... $\endgroup$ – MarcoB Feb 15 '19 at 17:28
  • 2
    $\begingroup$ Is this what you want? Select[Partition[data, 6], #[[3, 2]] > 10 &] $\endgroup$ – march Feb 15 '19 at 17:48
  • $\begingroup$ @march : that's almost what I wanted. I just need to remove partition afterwards. Could you please tell me how to do that? $\endgroup$ – John Taylor Feb 23 '19 at 0:46
  • $\begingroup$ Select[Partition[data, 6], #[[3, 2]] > 10 &]~Flatten~1. $\endgroup$ – march Feb 26 '19 at 19:02
1
$\begingroup$
partitions = Partition[data, 6];
Pick[partitions, UnitStep[partitions[[All, 3, 2]] - 10], 1]

{{{1, 2, 3}, {1, 9, 6}, {1, 12, 6}, {1, 5, 6}, {1, 6, 3}, {1, 5, 5}}}

You can also use undocumented 6-argument form of Partition:

Partition[data, 6, 6, 1, {}, If[{##}[[3, 2]] > 10, {##}, Nothing] &]

{{{1, 2, 3}, {1, 9, 6}, {1, 12, 6}, {1, 5, 6}, {1, 6, 3}, {1, 5, 5}}}

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