Re: Select and Cases Give Different Answers

• To: mathgroup at smc.vnet.net
• Subject: [mg99204] Re: Select and Cases Give Different Answers
• From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
• Date: Wed, 29 Apr 2009 06:41:43 -0400 (EDT)
• References: <gt6fhd\$rnu\$1@smc.vnet.net>

```For some reason or another the != test returns undecided for
comparisons of rationals and complex numbers with strings, but not for
integers and reals with strings

In[6]:= 1/2 != "NA"

Out[6]= 1/2 != "NA"

this, on its turn, influences your Select results.

In[7]:= 1/2 =!= "NA"

Out[7]= True

I'm unable to come up with a good reason for this behavior so I am
tempted to say this is a bug.

Cheers -- Sjoerd

On Apr 28, 10:42 am, Gregory Lypny <gregory.ly... at videotron.ca> wrote:
> Hello everyone,
>
> Suppose I have the following list that is a mixture of the string "NA"
> and five numeric quantities.
>
>         theList = {"NA", "NA", -0.01315, 0.0120957, -1/41, 0.00=
625, "NA",
> "NA", 5/8,  "NA"}
>
> I want to weed out the NAs, and all of the following
>
>         Cases[theList, _?NumericQ]
>
>         DeleteCases[theList, _?StringQ]
>
>         Select[theList, # =E2=88=88 Reals &]
>
>         Select[theList, # =!= "NA" &]
>
> work fine because each returns {-0.01315, 0.0120957, -(1/41), 0.00625,
> 5/8}.
>
> But I don't understand why Unequal, when used as the criterion for
> Select as in
>
>         Select[theList, # != "NA" &],
>
> fails to return the rationals, and I get only three elements
> {-0.01315, 0.0120957, 0.00625}.  I'd appreciate any clarification on
> the difference between UnsameQ and Unequal because my inclination in
> most circumstances is to use an equal sign or an unequal sign to make
> simple comparisons yet it doesn't give me the answer I expect, and I'd
> hate to make a costly mistake somewhere down the road!
>
> Regards,
>
>         Gregory

```

• Prev by Date: Re: Select and Cases Give Different Answers
• Next by Date: Re: NDSolve initial value problem