|
[Date Index]
[Thread Index]
[Author Index]
Re: Picking Off Lists That Have No Numbers
- To: mathgroup at smc.vnet.net
- Subject: [mg99523] Re: Picking Off Lists That Have No Numbers
- From: Ulvi Yurtsever <a at b.c>
- Date: Thu, 7 May 2009 06:35:07 -0400 (EDT)
- References: <gtrl29$1o5$1@smc.vnet.net>
Gregory Lypny <gregory.lypny at videotron.ca> wrote in news:gtrl29$1o5$1
@smc.vnet.net:
> Hi everyone,
>
> 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}
>
> If I use Real or Rational for the criterion, I get the right answers,
> but that's no good if you have some lists that are mixtures of strings
> and reals and others that are mixtures of strings and rationals.
I don't think _Number is a built-in pattern match,
unlike _Real, _Rational, _String, or _Integer.
You can use _?NumberQ instead:
In[29]:= FreeQ[#, _?NumberQ] & /@ {{"NA", 2.3, 3/8}, {"NA", "NA", "NA"}}
Out[29]= {False, True}
In[30]:= MemberQ[#, _?NumberQ] & /@ {{"NA", 2.3, 3/8}, {"NA", "NA", "NA"}}
Out[30]= {True, False}
In[32]:=
Count[#, _?NumberQ] == 0 & /@ {{"NA", 2.3, 3/8}, {"NA", "NA", "NA"}}
Out[32]= {False, True}
Ulvi
Prev by Date:
copy and paste to other programs
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
|