MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Select and Cases Give Different Answers

On 4/28/09 at 4:42 AM, gregory.lypny at (Gregory Lypny)


>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!


In[8]:= 1/4 != "NA"

Out[8]= 1/4!=NA

That is Mathematica cannot determine whether the rational 1/4 is
equal or not to the string "NA". Since, this comparison doesn't
return True, the rationals in the list are not returned

To me the real surprise here is Mathematica returns true when
comparing the string "NA" to a real.

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