1
$\begingroup$

I'm having some troubles manipulating a nested list:

{{2.5285, 2.54381}, {1.77463, 1.0246}, {1.30668, 1.31949}, {0.986982, 1.78699}, 
 {1.71224, 0.00986564}, {0.733888, 0.768184}, {0.0570823, 1.71373}}

I need to remove any list whose elements are not in some Interval[{0, x}], if the interval is [0, 1] I should keep only {{0.733888, 0.768184}}

The nested list may be of n elements {{a1, b1, d1, ..., n1}, {a2, b2, ..., n2}, ...}

Any idea?

$\endgroup$

1 Answer 1

4
$\begingroup$

With

list = {{2.5285, 2.54381}, {1.77463, 1.0246}, {1.30668, 1.31949}, {0.986982, 1.78699}, 
        {1.71224, 0.00986564}, {0.733888, 0.768184}, {0.0570823, 1.71373}};

Try:

Select[VectorQ[#, 0 <= # <= 1 &]&]@ list

(* Out: {{0.733888, 0.768184}} *)

You could wrap this in a function for convenience and to change the upper limit:

Clear[selectinterval]
selectinterval[upperlimit_][list_] := Select[list, VectorQ[#, 0 <= # <= upperlimit &] &]

which you can use as follows to achieve the same result:

selectinterval[1][list]
$\endgroup$

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.