Re: How Do You Reduce Multiple Elements in a List?

*To*: mathgroup at smc.vnet.net*Subject*: [mg33885] Re: How Do You Reduce Multiple Elements in a List?*From*: "Allan Hayes" <hay at haystack.demon.co.uk>*Date*: Sun, 21 Apr 2002 06:12:41 -0400 (EDT)*References*: <a9r3ve$ltc$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Bob, <<Statistics`DataManipulation` data={1, 1, 1, 1, 1, 2, 2, 2, 4, 4, 4, 4, 4, 4}; Frequencies[data] {{5,1},{3,2},{6,4}} Or, own code: {Length[#],First[#]}&/@Split[Sort[data]] {{5,1},{3,2},{6,4}} In this particular case Sort is not needed {Length[#],First[#]}&/@Split[data] {{5,1},{3,2},{6,4}} -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565 "Bob Harris" <nitlion at mindspring.com> wrote in message news:a9r3ve$ltc$1 at smc.vnet.net... > Howdy, > > This seems like such a simple thing, yet I've search through the big book > trying to figure it out. Perhaps someone can help me... > > Given a list of integers that generally contains the same number many times, > I'd like to reduce it to a list that just gives me the number/count pairs. > For example, I'd like to convert the list > {1, 1, 1, 1, 1, 2, 2, 2, 4, 4, 4, 4, 4, 4} > into > {{1,5}, {2,3}, (4,6}} > > Is there a built-in function to do this? Seems like a histogramming > operation, but I get no useful matches from ?*Hist*. > > Thanks, > Bob H > >