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: [mg96868] Re: [mg96798] Counting Categories
  • From: Darren Glosemeyer <darreng at wolfram.com>
  • Date: Thu, 26 Feb 2009 07:57:57 -0500 (EST)
  • References: <200902250903.EAA15666@smc.vnet.net>

Gregory Lypny 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
>
>
>
>   

You mentioned Cases, but I think you meant Count. Tally will do the 
counting you described.

In[1]:= data = Transpose[{RandomChoice[{red, blue, green}, 20],
           RandomChoice[{small, medium, big}, 20]}];

In[2]:= Tally[data]

Out[2]= {{{blue, medium}, 6}, {{green, medium}, 2}, {{red, medium}, 2}, 
{{green, small}, 5},
 
 >    {{blue, small}, 1}, {{red, small}, 2}, {{red, big}, 2}}


Darren Glosemeyer
Wolfram Research


  • Prev by Date: Re: Map and functional constructs to replace iterative statements
  • Next by Date: Re: Inverse of a Big Matrix
  • Previous by thread: Re: Counting Categories
  • Next by thread: Re: Counting Categories