1
$\begingroup$

This question already has an answer here:

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"}}} 
$\endgroup$

marked as duplicate by tkott, bbgodfrey, Sjoerd C. de Vries, Karsten 7., ciao Mar 23 '15 at 22:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ Did you try DeleteCases? $\endgroup$ – Karsten 7. Mar 23 '15 at 20:07
  • $\begingroup$ See possible duplicates: mathematica.stackexchange.com/questions/2486/…, mathematica.stackexchange.com/questions/16676/… $\endgroup$ – tkott Mar 23 '15 at 20:37
  • $\begingroup$ 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.) $\endgroup$ – ciao Mar 25 '15 at 2:55
  • $\begingroup$ Thanks. I noticed as soon as I posted the data that there was an extra set of "{}" $\endgroup$ – Iza Mar 25 '15 at 13:06
2
$\begingroup$
list = {{1, 3}, {1, "NS"}, {"NS", 5}, {"NS", "NS"}}

Cases[list, {__?NumericQ}]

gives:

{{1, 3}}
$\endgroup$
1
$\begingroup$

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

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}}*)
$\endgroup$
  • $\begingroup$ the levelspec has to by a positive Integer at DeleteCases. $\endgroup$ – sacratus Mar 23 '15 at 22:07
  • $\begingroup$ and i think he dont wants to have single x or y values, only valid pairs {x,y} i guess. $\endgroup$ – sacratus Mar 23 '15 at 22:15
-3
$\begingroup$
Select[list, (#[[1]]!= "NS") && (#[[2]]!= "NS") &]
$\endgroup$
  • 1
    $\begingroup$ 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"? $\endgroup$ – Verbeia Mar 23 '15 at 22:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.