# Matching a case when one element in a pair is Null

I've got a dataset of laitutdes and longitudes. Unfortunately, some of the dataset was from when a time when lat/longs weren't constantly recorded. So I need to remove the invalid data before working with it.

I've already removed the cases with no lat/long at all, but I'm having trouble with the cases where only one of the values are missing. Why this is the case in the original data, I'm not sure.

So I've used Deletecases on my original data,

DeleteCases[originaldata, {Null, Null}]


So now I have something like this:

mylist =
{{Null, 53.}, {-5.52167, 105.308}, {-6.70833, 39.665}, {-1., 116.},
{5.58333, 97.0833}, {-6.25117, 108.446}, {22.1783, 91.7767}};


How would I delete any tuples with either value Null?

• Try: DeleteCases[mylist, {Null, _} | {_, Null}]. This will also take care of the case where both entries are Null so you only have to use DeleteCases once. Oct 20 '14 at 5:07
• Since your entries appear to be all Real you can simply use Cases[mylist, {_Real, _Real}] Oct 20 '14 at 5:16
• {_Real, _Real} did it for me. I was attempting to use {_NumericQ, _NumericQ} which obviously didn't work.
– user4860
Oct 20 '14 at 17:55
• You can use NumericQ but be aware that you'll have to put ? before it. i.e. {_?NumericQ, _?NumericQ} Oct 20 '14 at 18:01

RunnyKine's comment written up as a answer.

DeleteCases[mylist, {Null, _} | {_, Null}].


This will also take care of the case where both entries are Null, so you only have to use DeleteCases once.

However, since your entries appear to be all reals, you might use

Cases[mylist, {_Real, _Real}


But if some of your numeric values don't have head real, then

Cases[mylist, {_?NumericQ, _?NumericQ}]


Also consider:

DeleteCases[mylist, {___, Null, ___}]


Or:

Select[mylist, FreeQ[Null]]  (* v10 operator syntax *)