1
$\begingroup$

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

For example.

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

gives me

b = {2}

As the Indeterminate value is contained in the nested list at position 2 of a.

$\endgroup$
1
  • $\begingroup$ "Nested list" can comprise a quite broad range of expressions. Do you mean a list of flat lists? Or is deeper nesting possible: {{1,2,3},{4,5,Indeterminate},{7,{8,Indeterminate},9}} --> {{2}, {3,2}}? And is that the desired output? $\endgroup$
    – Michael E2
    Commented Nov 27, 2019 at 17:11

2 Answers 2

4
$\begingroup$

All-level function:

indetList = Position[#, {___, Indeterminate, ___}] &

Examples:

indetList[{{1, 2, 3}, {4, 5, Indeterminate}, {7, 8, 9}, {10, 11, 12}}]
(*  {{2}}  *)

indetList[{{1, 2, 3}, {4, 5, Indeterminate}, {7, {8, Indeterminate}, 9}}]
(*  {{2}, {3, 2}}  *)

indetList[{
  {1, 2, 3},
  {4, 5, Indeterminate},
  {7, {8, Indeterminate}, Indeterminate}}]
(*  {{2}, {3, 2}, {3}}  *)

Level-one function:

indetElems = Pick[Range@Length@#, Not@*FreeQ[Indeterminate] /@ #] &

Examples:

indetElems[{{1, 2, 3}, {4, 5, Indeterminate}, {7, 8, 9}, {10, 11, 12}}]
(*  {2}  *)

indetElems[{{1, 2, 3}, {4, 5, Indeterminate}, {7, {8, Indeterminate}, 
   9}}]
(*  {2, 3}  *)

indetElems[{
  {1, 2, 3},
  {4, 5, Indeterminate},
  {7, {8, Indeterminate}, Indeterminate}}]
(*  {2, 3}  *)
$\endgroup$
3
$\begingroup$
a = {{1, 2, 3}, {4, 5, Indeterminate}, {7, 8, 9}, {10, 11, 12}, {13, 
    Indeterminate, 15}};

b = Position[a, _?(! FreeQ[#, Indeterminate] &), 1]

(* {{2}, {5}} *)

or

b = Position[a, _?(MemberQ[#, Indeterminate] &), 1]

(* {{2}, {5}} *)
$\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.