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

MathGroup Archive 2009

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

Search the Archive

Re: Counting Categories

  • To: mathgroup at smc.vnet.net
  • Subject: [mg96885] Re: [mg96798] Counting Categories
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Thu, 26 Feb 2009 08:01:06 -0500 (EST)
  • References: <200902250903.EAA15666@smc.vnet.net>
  • Reply-to: drmajorbob at bigfoot.com

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: Eigensystem[hermitianMatrix] sometimes returns non-orthonormal
  • Next by Date: Re: Series of Percentage Changes
  • Previous by thread: Re: Counting Categories
  • Next by thread: Re: Counting Categories