Re: Counting Categories

• To: mathgroup at smc.vnet.net
• Subject: [mg96887] Re: [mg96798] Counting Categories
• From: Gregory Lypny <gregory.lypny at videotron.ca>
• Date: Thu, 26 Feb 2009 08:01:30 -0500 (EST)
• References: <200902250903.EAA15666@smc.vnet.net>

```Gather does it without the counts.  Tally does it and includes the
counts.  But yours is best because neither Gather nor Tally gives the
results in the order of the original tuples, so there'd be the
overhead of (somehow) sorting, and rearranging to get a nice
contingency table.

Gregory

On Wed, Feb 25, 2009, at 2:30 PM, DrMajorBob wrote:

> I don't see an easy way to use GatherBy for this... but there may be
> one.
>
> Bobby
>
> On Wed, 25 Feb 2009 07:14:08 -0600, Gregory Lypny <gregory.lypny at videotron.ca
> > wrote:
>
>> This is so cool.  Thank you.  I also found a new function yesterday
>> called GatherBy.  Not sure if it does the same thing.
>>
>> Regards,
>>
>> 	Gregory
>>
>>
>> On Wed, Feb 25, 2009, at 5:21 AM, DrMajorBob wrote:
>>
>>> Something like:
>>>
>>> colors = {red, yellow, green, blue};
>>> sizes = {small, medium, large};
>>> randomColor := RandomChoice@colors
>>> randomSize := RandomChoice@sizes
>>> pairs = Table[{randomColor, randomSize}, {50}];
>>>
>>> Partition[Count[pairs, #] & /@ Tuples[{colors, sizes}],
>>> Length@sizes]
>>>
>>> {{5, 3, 3}, {3, 6, 3}, {8, 1, 2}, {5, 4, 7}}
>>>
>>> or
>>>
>>> Apply[Count[pairs, {##}, 1] &, Outer[List, colors, sizes], {2}]
>>>
>>> {{5, 3, 3}, {3, 6, 3}, {8, 1, 2}, {5, 4, 7}}
>>>
>>> Bobby
>>>
>>> On Wed, 25 Feb 2009 03:03:33 -0600, Gregory Lypny <gregory.lypny at videotron.ca
>>> > wrote:
>>>
>>>> Hello Everyone,
>>>>
>>>> I'm trying to do multivariate category counts in the way that
>>>> used to
>>>> be handled by CategoryCounts but is now replaced by Cases.  The
>>>> example in Help simply applies Cases twice to find the count of
>>>> elements in a list that are numbers and the count that is even.
>>>>
>>>> Map[Cases[{a, b, c, 1, 2, d, 3}, #] &, {_?NumberQ, _?EvenQ}]
>>>>
>>>> {{1, 2, 3}, {2}}
>>>>
>>>> But what if I have many rows of observations on two dimensions
>>>> (columns) such as red, blue, green, and small, medium, big?  I'd
>>>> like
>>>> to be able categorize them accordingly as the count of small and
>>>> red,
>>>> medium and red, big and red, and so on.  Any way to do that?
>>>>
>>>> 	Regards,
>>>>
>>>> 		Gregory
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>> --DrMajorBob at longhorns.com
>>
>
>
>
> --
> DrMajorBob at longhorns.com

```

• Prev by Date: Re: Re: Manipulating list of functions
• Next by Date: Re: Re: listing user defined, independent variables
• Previous by thread: Re: Counting Categories
• Next by thread: Re: Counting Categories