Removing missing data from a list

I have a list like this (experimental data):

{{0.04, 22.4, 43.286, 99.998}, {0.04, 22.4, 43.288, 99.997}, {0.04,22.4, 43.289, 99.997}, {588.24, "", "", 76.519}, {588.24, "", "", 76.519}, {588.24, "", "",76.519}, {588.24, "", "", 76.519}, {588.24, "", "", 76.519}, {},{0.05, 22.4, 43.293, 99.997}}


I want to remove every sublist that has a missing value, so if a sublist is like {588.24, "", "", 76.519}, it should be removed, it is like {}, it should be removed. Can this be done in a simple way?

• Try: Map[If[MemberQ[#, ""] || # == {}, Nothing, #] &, data, 1] Commented Aug 26, 2022 at 6:43

I want to remove every sublist that has a missing value

There are at least 10 ways to do this in Mathematica. One way could be

data = {{0.04, 22.4, 43.286, 99.998}, {0.04, 22.4, 43.288,
99.997}, {0.04, 22.4, 43.289, 99.997}, {588.24, "", "",
76.519}, {588.24, "", "", 76.519}, {588.24, "", "",
76.519}, {588.24, "", "", 76.519}, {588.24, "", "",
76.519}, {}, {0.05, 22.4, 43.293, 99.997}}

DeleteCases[data, x_ /; Or[MemberQ[x, ""], Length[x] == 0]]


gives

{{0.04, 22.4, 43.286, 99.998}, {0.04, 22.4, 43.288, 99.997}, {0.04,
22.4, 43.289, 99.997}, {0.05, 22.4, 43.293, 99.997}}


You can match the data you need

data = {{0.04, 22.4, 43.286, 99.998}, {0.04, 22.4, 43.288,
99.997}, {0.04, 22.4, 43.289, 99.997}, {588.24, "", "",
76.519}, {588.24, "", "", 76.519}, {588.24, "", "",
76.519}, {588.24, "", "", 76.519}, {588.24, "", "",
76.519}, {}, {0.05, 22.4, 43.293, 99.997}};
data // Cases[{_Real ..}]

Pick[data, FreeQ[#, ""] & /@ data] /. {} -> Nothing


OR

pos = Position[data, x_ /; Length[x] > 0 && FreeQ[x, ""]]
Extract[pos][data]


Result:

{{0.04, 22.4, 43.286, 99.998}, {0.04, 22.4, 43.288, 99.997}, {0.04,
22.4, 43.289, 99.997}, {0.05, 22.4, 43.293, 99.997}}


Another way is as follows:

DeleteCases[Map[If[NumericQ[#] === True, #, Nothing] &, data, {-1}], {}]

(*{{0.04, 22.4, 43.286, 99.998}, {0.04, 22.4, 43.288, 99.997}, {0.04, 22.4, 43.289, 99.997}, {588.24, 76.519}, {588.24, 76.519}, {588.24, 76.519}, {588.24, 76.519}, {588.24, 76.519}, {0.05, 22.4, 43.293, 99.997}}*)

list =
{{0.04, 22.4, 43.286, 99.998}, {0.04, 22.4, 43.288, 99.997},
{0.04, 22.4, 43.289, 99.997}, {588.24, "", "", 76.519},
{588.24, "", "", 76.519}, {588.24, "", "", 76.519},
{588.24, "", "", 76.519}, {588.24, "", "", 76.519},
{}, {0.05, 22.4, 43.293, 99.997}};


Three more solutions / modifications

Using SequenceSplit (new in 11.3)

Catenate @ SequenceSplit[list, {{___, "", ___} | {}}]


Using DeleteCases with OrderlessPatternSequence

DeleteCases[list, {OrderlessPatternSequence[__, ""]} | {}]


Using Cases

Cases[list, {__?NumberQ}]


All produce

{{0.04, 22.4, 43.286, 99.998}, {0.04, 22.4, 43.288, 99.997}, {0.04, 22.4, 43.289, 99.997}, {0.05, 22.4, 43.293, 99.997}}

list =
{{0.04, 22.4, 43.286, 99.998}, {0.04, 22.4, 43.288, 99.997},
{0.04, 22.4, 43.289, 99.997}, {588.24, "", "", 76.519},
{588.24, "", "", 76.519}, {588.24, "", "", 76.519},
{588.24, "", "", 76.519}, {588.24, "", "", 76.519},
{}, {0.05, 22.4, 43.293, 99.997}};


Using Replace at level 1:

Replace[data, s : Except[{__?NumberQ}] :> Nothing, {1}]


{{0.04, 22.4, 43.286, 99.998}, {0.04, 22.4, 43.288, 99.997},
{0.04, 22.4, 43.289, 99.997}, {0.05, 22.4, 43.293, 99.997}}

Or using Replace at level 2 with Cases:

Cases[{__}]@Replace[data, s : Except[_?NumberQ] :> Nothing, {2}]

{{0.04, 22.4, 43.286, 99.998}, {0.04, 22.4, 43.288, 99.997},
{0.04, 22.4, 43.289, 99.997}, {588.24, 76.519}, {588.24, 76.519},
{588.24, 76.519}, {588.24, 76.519}, {588.24, 76.519},
{0.05, 22.4, 43.293, 99.997}}