# Delete Missing data from coordinate sets

I have a list of pairs of coordinates, where some are missing.

coordinates = {
{{1, 1}, {1, 2}},
{{3, 4}, {5, 5}},
{{1, 2}, Missing[]},
{{9, 8}, {7, 7}},
{Missing[], {2, 3}}
}


I am trying to remove the pairs containing missing coordinates, to get

coordinates = {
{{1, 1}, {1, 2}},
{{3, 4}, {5, 5}},
{{9, 8}, {7, 7}},
}


I tried

coordinates = DeleteCases[coordinates, MemberQ[#, _Missing] &]


but that did not work. But the function MemberQ works on pairs directly:

MemberQ[coordinates[[1]], _Missing] (* returns False *)
MemberQ[coordinates[[3]], _Missing] (* returns True *)


What did I do wrong?

• DeleteCases[coordinates, _?(MemberQ[#, _Missing] &)] or DeleteCases[coordinates, x_ /; MemberQ[x, _Missing]] work Jun 6 '14 at 17:32
• Related: (1234), (2655), (29159) Jun 7 '14 at 14:21

coordinates = {{{1, 1}, {1, 2}}, {{3, 4}, {5, 5}}, {{1, 2}, Missing[]}, {{9, 8}, {7, 7}}, {Missing[], {2, 3}}};


The second argument to DeleteCases must be a pattern not a boolean.

correctedCoordinates = DeleteCases[coordinates, _?(MemberQ[#, _Missing] &)]


{{{1, 1}, {1, 2}}, {{3, 4}, {5, 5}}, {{9, 8}, {7, 7}}}

Similarly with Cases

correctedCoordinates == Cases[coordinates, _?(FreeQ[#, _Missing] &)]


True

Whereas, Select requires a boolean.

correctedCoordinates == Select[coordinates, FreeQ[#, _Missing] &]


True

• Yes, you're right. I was mistaken about what was going wrong. Do you know what happened to MathGroup? No new messages since May 22. Jun 6 '14 at 18:31
• Presumably, most/all of the traffic migrated here and the moderator fell asleep. :-) Jun 6 '14 at 18:54
DeleteCases[coordinates, {___, Missing[], ___}]


Or (slower)

Cases[coordinates, {{__?NumberQ}, {__?NumberQ}}]


I like this style because of its flexibility in more complicated cases.

With

x = Join @@ Table[coordinates, {10^5}];


Eldo DeleteCases : 0.22 sec.
Szabolcs: : 0.86 sec.
Bob Hanlon DeleteCases : 0.95 sec.

Bob Hanlon has the answer, but merely as a supplement: if your data is as you show I would simply use Select and MatrixQ.

Select[coordinates, MatrixQ]

{{{1, 1}, {1, 2}}, {{3, 4}, {5, 5}}, {{9, 8}, {7, 7}}}


You could also use DeleteMissing:

DeleteMissing[coordinates, 1, 1]


{{{1, 1}, {1, 2}}, {{3, 4}, {5, 5}}, {{9, 8}, {7, 7}}}

but it's more than 4 times slower on my PC than the solution provided in the answer by Mr.Wizard.