Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2001
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

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

Search the Archive

Re: Any better way for finding frequencies of list entries?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg26941] Re: Any better way for finding frequencies of list entries?
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Sat, 27 Jan 2001 20:00:09 -0500 (EST)
  • References: <94tlor$let@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Domi,
Variants:

1)

See the function Frequencies in the package

    <<Statistics`DataManipulation`

2)

pi = RealDigits[N[Pi, 57]][[1]]

{3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3,
\
3, 8, 3, 2, 7, 9, 5, 0, 2, 8, 8, 4, 1, 9, 7, 1, 6, 9, 3, 9, 9, 3, 7, 5, 1,
0, \
5, 8, 2, 0, 9, 7}

{Firsr[#], Length[#]} & /@ Split[Sort[pi]]

{{0, 3}, {1, 5}, {2, 6}, {3, 9}, {4, 4}, {5, 6}, {6, 4}, {7, 5}, {8, 6}, {9,
    9}}

One problem with the above would be if not all the digits 0...9 occured and
we wanted zero occurences recorded. Here is a generalization that deals with
this.

HowManyIn[x_, y_] := {First[#], Length[Rest[#]]} & /@ Split[Sort[Join[x,
y]]]

HowManyIn[{a, b, c}, {a, b, a}]

{{a, 2}, {b, 1}, {c, 0}}

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

"Domi" <doud25 at caramail.com> wrote in message
news:94tlor$let at smc.vnet.net...
> Hello Mathematica experts out there,
>
> I want to determine the frequencies of the entries in a list of integers
>
> For example, the following piece of code seems to work with Pi:
> pi = Join
>     [ {3}, ToExpression[Characters[StringDrop[ToString[N[Pi, 57]], {1,
> 2}]]]]
> Table[{i, Count[pi, i]}, {i, 0, 9}]
>
>     {{0, 3}, {1, 5}, {2, 6}, {3, 9}, {4, 4}, {5, 6}, {6, 4}, {7, 5},
>     {8, 6}, {9,   9}}
>
> Question: Is there a more elegant way to do that?
>
> Regards from Domi.
>






  • Prev by Date: RE: Any better way for finding frequencies of list entries?
  • Next by Date: Re: Mathematica 4.1 + Linux + gnome/sawfish
  • Previous by thread: RE: Any better way for finding frequencies of list entries?
  • Next by thread: Re: Any better way for finding frequencies of list entries?