Re: Picking Off Lists That Have No Numbers
- To: mathgroup at smc.vnet.net
- Subject: [mg99502] Re: [mg99471] Picking Off Lists That Have No Numbers
- From: Gregory Lypny <gregory.lypny at videotron.ca>
- Date: Thu, 7 May 2009 06:31:15 -0400 (EDT)
- References: <200905060925.FAA01807@smc.vnet.net>
Thank you, Andrzej,
So now I'm starting to get the distinction between Q and non-Q criteria.
Gregory
On Wed, May 6, 2009, at 7:25 AM, Andrzej Kozlowski wrote:
> This time its different. You cannot make a pattern _Number because
> Number is not the Head of anything in Mathematica. So
>
> FreeQ[{1}, _Number]
> True
>
> But
>
> FreeQ[{1}, _?NumberQ]
> False
>
> which is quite different =85
>
> With that change:
>
> FreeQ[#, _?NumberQ] & /@ {{"NA", 2.3, 3/8}, {"NA", "NA", "NA"}}
> {False, True}
>
> and
>
> MemberQ[#, _?NumberQ] & /@ {{"NA", 2.3, 3/8}, {"NA", "NA", "NA"}}
> {True, False}
>
> No difference.
>
> Note also that Real and Rational (unlike Number) are actually Heads =
> so everything works fine in those cases.
>
> Andrzej Kozlowski
>
>
>
> On 6 May 2009, at 18:25, Gregory Lypny wrote:
>
>> 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.
>>
>> FreeQ[#, _Real] && FreeQ[#, _Rational]
>> & /@ {{"NA", 2.3, 3/8}, {"NA", "NA", "NA"}, {"NA", 2.3, "NA"}, {"NA",
>> 2.3, 9.4}}
>>
>> Now this works.
>>
>> Count[#, _String] == Length[#] & /@ {{"NA", 2.3, 3/8}, {"NA", =
"NA",
>> "NA"}}
>>
>> {False, True}
>>
>> But this does not!
>>
>> Count[#, _Number] == 0 & /@ {{"NA", 2.3, 3/8}, {"NA", "NA", =
"NA"}}
>>
>> {True, True}
>>
>> I don't mean to be a pain, but it is important in my sample selection
>> procedures to be able to make the distinction between strings and
>> numbers, so I'd be interested in knowing whether I'm misunderstanding
>> properties such as Number or Numeric (don't really know the
>> difference) or this is a bug.
>>
>>
>> Gregory
>>
>
- References:
- Picking Off Lists That Have No Numbers
- From: Gregory Lypny <gregory.lypny@videotron.ca>
- Picking Off Lists That Have No Numbers