4
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – RunnyKine Oct 20 '14 at 5:07
  • 2
    $\begingroup$ Since your entries appear to be all Real you can simply use Cases[mylist, {_Real, _Real}] $\endgroup$ – RunnyKine Oct 20 '14 at 5:16
  • $\begingroup$ {_Real, _Real} did it for me. I was attempting to use {_NumericQ, _NumericQ} which obviously didn't work. $\endgroup$ – user4860 Oct 20 '14 at 17:55
  • $\begingroup$ You can use NumericQ but be aware that you'll have to put ? before it. i.e. {_?NumericQ, _?NumericQ} $\endgroup$ – RunnyKine Oct 20 '14 at 18:01
5
$\begingroup$

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}]
$\endgroup$
6
$\begingroup$

Also consider:

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

Or:

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

Your Answer

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