MathGroup Archive 2009

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

Search the Archive

Re: Counting Categories

  • To: mathgroup at
  • Subject: [mg96841] Re: Counting Categories
  • From: "Sjoerd C. de Vries" <sjoerd.c.devries at>
  • Date: Thu, 26 Feb 2009 07:53:01 -0500 (EST)
  • References: <go31gb$f8r$>

Hi Gregory,

To avoid confusion: CategoryCount is not replaced with the Cases
constructiom you showed. That's the function CategoryLists.
CategoryCount is done with Count instead of Cases.

However, what you want can be easily done with Tally:

In[187]:= data =
 Table[{RandomChoice[{red, green, blue}],
   RandomChoice[{small, big, medium}]}, {20}]

Out[187]= {{green, big}, {red, medium}, {red, big}, {red, big}, {blue,
   medium}, {blue, big}, {blue, small}, {green, big}, {red,
  medium}, {red, medium}, {blue, big}, {red, medium}, {green,
  big}, {green, small}, {red, medium}, {blue, small}, {green,
  big}, {red, medium}, {red, medium}, {red, medium}}

In[188]:= Tally[data]

Out[188]= {{{green, big}, 4}, {{red, medium}, 8}, {{red, big},
  2}, {{blue, medium}, 1}, {{blue, big}, 2}, {{blue, small},
  2}, {{green, small}, 1}}

Cheers -- Sjoerd

On Feb 25, 11:03 am, Gregory Lypny < at> 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

  • Prev by Date: Re: Counting Categories
  • Next by Date: Re: Re: Coolest Mathematica trick you'll see this month
  • Previous by thread: Re: Counting Categories
  • Next by thread: N00b help needed: Graphics