Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: Picking Off Lists That Have No Numbers

  • To: mathgroup at smc.vnet.net
  • Subject: [mg99545] Re: Picking Off Lists That Have No Numbers
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Thu, 7 May 2009 06:39:08 -0400 (EDT)

On 5/6/09 at 5:25 AM, gregory.lypny at videotron.ca (Gregory Lypny)
wrote:

>In a previous thread, "Select and Cases Give Different Answers," I
>discussed a bug, confirmed by others on the list and which Daniel
>Lichtblau of Wolfram said has been fixed in the development kernel,
>and I wonder whether we have the same problem here.

>I want to know if a list has no numbers in it.  Here I get the wrong
>answer for the first list.

>FreeQ[#, _Number] & /@ {{"NA", 2.3, 3/8}, {"NA", "NA", "NA"}}

>yields {True, True} And same here.

>MemberQ[#, _Number] & /@ {{"NA", 2.3, 3/8}, {"NA", "NA", "NA"}}

>{False, False}

Both FreeQ and MemberQ are operating as documented in these
examples. If you do

In[18]:= Union@
  Flatten@Map[Head, {{"NA", 2.3, 3/8}, {"NA", "NA", "NA"}}, {2}]

Out[18]= {Rational,Real,String}

you see that none of the elements in either list have the head
Number. So, FreeQ correctly reports both list have nothing
matching the specified pattern. Similarly, MemberQ reports
anything matching this pattern is not a member of either list.

>If I use Real or Rational for the criterion, I get the right
>answers,

Which of course works because there are elements with head Real
and Rational in these lists.

The basic problem is there is nothing built-in to Mathematica
with the head Number. To check for numbers with say FreeQ you
need to do:

In[19]:= FreeQ[#, _?NumericQ] & /@ {{"NA", 2.3, 3/8}, {"NA", "NA",
    "NA"}}

Out[19]= {False,True}

or with MemberQ

In[20]:= MemberQ[#, _?NumericQ] & /@ {{"NA", 2.3, 3/8}, {"NA", "NA",
    "NA"}}

Out[20]= {True,False}



  • Prev by Date: Re: Given a matrix, find position of first non-zero element in each row
  • Next by Date: Re: Given a matrix, find position of first non-zero element in each
  • Previous by thread: Re: Picking Off Lists That Have No Numbers
  • Next by thread: Re: Picking Off Lists That Have No Numbers