Re: Counting Categories
- To: mathgroup at smc.vnet.net
- Subject: [mg96833] Re: [mg96798] Counting Categories
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Thu, 26 Feb 2009 07:51:33 -0500 (EST)
- References: <200902250903.EAA15666@smc.vnet.net>
- Reply-to: drmajorbob at bigfoot.com
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
- References:
- Counting Categories
- From: Gregory Lypny <gregory.lypny@videotron.ca>
- Counting Categories