1
$\begingroup$

The following works as intended:

DeleteMissing[{{a, 1}, {b, 2}, {c, Missing[]}, {d, 4}, {e, 
   Missing[]}, {f, 5}}, 1, 1]
DeleteMissing[{a -> 1, b -> Missing[], c -> 3, d -> Missing[]}]

However, an analogous code below does not work.

DeleteMissing[{{a, 1} -> bir, {b, 2} -> iki, {c, Missing[]} -> 
   uc, {d, 4} -> dort, {e, Missing[]} -> bes, {f, 5} -> alti}, 1, 1]

which is supposed to give me:

{{a, 1} -> bir, {b, 2} -> iki, {d, 4} ->dort,  {f, 5} -> alti}

Why?

$\endgroup$
4
$\begingroup$

Use All as the third argument in DeleteMissing:

DeleteMissing[{{a, 1} -> bir, {b, 2} -> iki, {c, Missing[]} -> uc, 
  {d, 4} -> dort, {e, Missing[]} -> bes, {f, 5} -> alti}, 1, All]

{{a, 1} -> bir, {b, 2} -> iki, {d, 4} -> dort, {f, 5} -> alti}

DeleteMissing[{{a, 1} -> bir, {b, 2} -> iki, {{{{c, Missing[]}}}} -> uc, 
 {d, 4} -> dort, {e, foo[{{bar@{Missing[]}}}]} -> bes, {f, 5} ->  alti}, 1, All]

{{a, 1} -> bir, {b, 2} -> iki, {d, 4} -> dort, {f, 5} -> alti}

$\endgroup$
  • $\begingroup$ I noticed that when I import data from Excel, texts such as Missing[] or na are imported as String and hence the above code does not work for strings (?), though it gives the right result for my question which does not have any string. $\endgroup$ – Tugrul Temel Jan 19 at 18:51
  • 3
    $\begingroup$ @TugrulTemel, you can replace "Missing[]" with Missing[] before you use DeleteMissing; i.e., DeleteMissing[ Replace[importeddata, "Missing[]" -> Missing[], All], 1, All]. Alternatively, you can use Select[FreeQ["Missing[]" | _Missing]][importeddata] $\endgroup$ – kglr Jan 19 at 19:06

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.