0
$\begingroup$

I have two lists of numbers, both have some entries that are Undefined. I am trying to use an If statement to replace any undefined elements in one list with its corresponding number in the same position in the second list.

Table[If[list2[[i]] === Undefined, list4[[i]], list2[[i]]], {i, 1, Length[list2]}]

However, this code seems to return list4. It's as though Mathematica is not recognizing the existence of a numerical element as the falsehood of Undefined

$\endgroup$
  • 1
    $\begingroup$ In version 11.3 in a fresh new notebook Clear[list2,list4]; list2={7,Undefined,5}; list4={1,2,3}; Table[If[list2[[i]] === Undefined, list4[[i]], list2[[i]]], {i, 1, Length[list2]}] returns {7, 2, 5} for me $\endgroup$ – Bill Apr 30 at 5:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.