# Delete data were y = "NS" in a list with elements {x, y} [duplicate]

I have a list of data {x, y}and not all of them have actual values. They show as {x, "NS"} or {"NS",y} or {"NS","NS"}. I'm trying to find a way to get rid of the sets with the "NS" so I can carry the analysis.

I am using Mathematica 10.

Here is my list of data, I think there is something wrong with the format because I've tried DeleteCases, Select, Cases... and I get "{}" as an output everytime. It might just need a simple fix, but I'm not sure what (I'm still a beginner in Mathematica).

{{{10.43, "NS"}, {10.42, "NS"}, {10.29, "NS"}, {9.03, "NS"}, {10.4, "NS"},
{3.61, 3.69}, {5.03, 4.85}, {8.8, 6.}, {8.51, "NS"}, {8.9, 8.7}, {"NS", "NS"},
{6.49, 7.}, {7.32, 7.54}, {7.67, 8.17}, {9.23, "NS"}, {9.36, 9.38}, {9.3, "NS"},
{8.94, 9.34}, {8.7, 8.79}, {8.41, 8.17}, {8.51, 8.58}, {8.66, 8.62}, {8.36, 8.28},
{8.36, 8.38}, {8.77, 8.79}, {10.49, 10.51}, {8.33, 8.22}, {8.41, 8.18}, {8.81, 8.42},
{4.92, 4.87}, {6.08, 6.21}, {6.19, 6.26}, {7.16, 7.31}, {"NS", "NS"}}}

• Did you try DeleteCases? Mar 23, 2015 at 20:07
• See possible duplicates: mathematica.stackexchange.com/questions/2486/…, mathematica.stackexchange.com/questions/16676/… Mar 23, 2015 at 20:37
• Re: your update example. Look at your list. It's not a list of lists, it's a list of a list of lists... you need to use the method(s) with appropriate level spec, or change the list (First@, etc.)
– ciao
Mar 25, 2015 at 2:55
• Thanks. I noticed as soon as I posted the data that there was an extra set of "{}"
– Iza
Mar 25, 2015 at 13:06

list = {{1, 3}, {1, "NS"}, {"NS", 5}, {"NS", "NS"}}

Cases[list, {__?NumericQ}]


gives:

{{1, 3}}


You may try:

list = {{1, 2}, {3, 4}, {10, "NS"}, {7, 6}, {4, 5}, {"NS", "NS"}, {7,
2}, {"NS", 9}, {9, 10}};

Select[list, AllTrue[#, NumericQ] &]


gives

{{1, 2}, {3, 4}, {7, 6}, {4, 5}, {7, 2}, {9, 10}}


As Karsten 7 mentioned, you can use DeleteCases like this:

DeleteCases[{{x, "NS"} , {"NS", y} , {"NS", "NS"}},x_String | {__String},-1]


Another way you can use Replace.

{{x, "NS"} , {"NS", y} , {"NS", "NS"}} //. _String | {} :> Sequence[]


Both give:

(*{{x}, {y}}*)

• the levelspec has to by a positive Integer at DeleteCases. Mar 23, 2015 at 22:07
• and i think he dont wants to have single x or y values, only valid pairs {x,y} i guess. Mar 23, 2015 at 22:15
Select[list, (#[[1]]!= "NS") && (#[[2]]!= "NS") &]

• Thanks for your attempt at an answer! Could you perhaps add a bit more explaining your approach and (ideally) how it compares to others? What if the non-numeric element isn't exactly "NS"? Mar 23, 2015 at 22:32