# Select data from a list

This code is to produce the list data from which I want to select some elements:

SeedRandom[1];
n = 10;
xmin = RandomInteger[{0, 20}, n];
ymin = RandomInteger[{0, 20}, n];
xmax = xmin + RandomInteger[{1, 10}, n];
ymax = ymin + RandomInteger[{1, 10}, n];

data =
Transpose[{xmin, ymin, xmax, ymax}]
/. {xmin_, ymin_, xmax_, ymax_} :> {{xmin, ymin}, {xmax, ymax}}

{{{5, 3}, {11, 6}}, {{0, 8}, {5, 12}}, {{7, 19}, {11, 29}},
{{0, 5}, {1, 11}}, {{2, 18}, {4, 20}}, {{3, 16}, {7, 22}},
{{0, 12}, {6, 15}}, {{0, 0}, {4, 4}}, {{16, 19}, {17, 29}},
{{14, 4}, {18, 6}}}

ydiff = data[[All, 2, 2]] - data[[All, 1, 2]]

{3, 4, 10, 6, 2, 6, 3, 4, 10, 2}


How can I select all data values where ydiff = (ymax - ymin) is for example greater than ydiffmin = 2 and less ydiffmax = 9?

The result should be:

{{{5, 3}, {11, 6}}, {{0, 8}, {5, 12}}, {{0, 5}, {1, 11}},
{{3, 16}, {7, 22}}, {{0, 12}, {6, 15}}, {{0, 0}, {4, 4}}}


Select[data, 2 < #[[2, 2]] - #[[1, 2]] < 9 &](* or *)
Pick[data, 2 < # < 9 & /@ ydiff]


all give

{{{5, 3}, {11, 6}}, {{0, 8}, {5, 12}}, {{0, 5}, {1, 11}}, {{3, 16}, {7, 22}}, {{0, 12}, {6, 15}}, {{0, 0}, {4, 4}}}

Szabolcs' BoolEval package comes to mind...

Needs["BoolEval"]
BoolPick[data, 2 < ydiff < 9]
`

{{{5, 3}, {11, 6}}, {{0, 8}, {5, 12}}, {{0, 5}, {1, 11}}, {{3,
16}, {7, 22}}, {{0, 12}, {6, 15}}, {{0, 0}, {4, 4}}}