4
$\begingroup$

I'd like to delete a whole nested list if one of the values in that list contains an "Indeterminate" value.

The link below provides a solution to delete individual "Indeterminate" values:

Delete indeterminate and infinite expressions

However, is there a way to delete a whole nested list, if at least one value of that list is Indeterminate.

For example.

a = {{1,2,3},{4,5,Indeterminate},{7,8,9},{10,11,12}}

Becomes

a = {{1,2,3},{7,8,9},{10,11,12}}
$\endgroup$
  • 2
    $\begingroup$ Consider also positive filtering, e.g. Cases[a, {__?NumericQ}]. $\endgroup$ – Mr.Wizard Nov 20 at 18:25
10
$\begingroup$

One way:

{{1, 2, 3}, {4, 5, Indeterminate}, {7, 8, 9}, {10, 11, 12}} /. 
  {___, Indeterminate, ___} -> Nothing
(* {{1, 2, 3}, {7, 8, 9}, {10, 11, 12}} *)

One other consideration: we generally recommend that you avoid using capital letters to begin your symbols, to avoid colliding with built-in symbols.

$\endgroup$
  • $\begingroup$ Thank you. I've corrected the the text based on your comment $\endgroup$ – reemodels Nov 20 at 15:07
7
$\begingroup$

You can use Select

A // Select[Not@MemberQ[#, Indeterminate] &]
(* {{1, 2, 3}, {7, 8, 9}, {10, 11, 12}} *)
$\endgroup$
5
$\begingroup$

Some other options

Select[ContainsNone[{Indeterminate}]][a]
(* {{1, 2, 3}, {7, 8, 9}, {10, 11, 12}} *)

Pick[a, ContainsNone[{Indeterminate}] /@ a]
(* {{1, 2, 3}, {7, 8, 9}, {10, 11, 12}}*)
$\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.