The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Integer Length Count
Replies: 3   Last Post: Nov 24, 2012 2:41 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Helen Read

Posts: 145
Registered: 9/27/10
Re: Integer Length Count
Posted: Nov 24, 2012 2:41 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 11/23/2012 3:30 AM, wrote:

> I use a function in SAS that takes, in my case, a billion different
> integers of varying length and counts the frequency of the length of
> each integer by converting the digits in the integers into alpha
> characters and counting the frequency of the right most position of the
> alpha character.
> I am trying to do more and more routine programming in Mathematica
> and after poking around in documentation for the past 4 hours have yet to
> find the parallel function in Mathematica for counting the integer
> frequency length in a big data set. My family wants me to drop
> everything and put the Turkey in the oven. My cat Sylvester even fell
> asleep on his back in front of the refrigerator with his little legs up
> in the air, so he want miss the transfer of the Turkey from the stove to
> the refrigerator. OH WELL -- IT'S SHOW TIME!
> Meanwhile, let me know any recommendations you have on a Mathematica
> function that parallels the SAS Function.

I'm not entirely certain what you are trying to do here (a small example
would help), but if I understand you correctly, have a look at

From the Documentation:

gives the number of digits in the base 10 representation of the integer n.

Under More Information, you will find that IntegerLength automatically
threads over lists. It ignores the sign of the integer.
IntegerLength[0], by the way, is 0.

Here's a small example, starting with a list of 25000 random integers in
the range from -10000 to 10000.

list = RandomInteger[{-10000, 10000}, 25000];

lengths = IntegerLength[list]; (* getting the lengths of all the
integers in the list *)

maxlength = Max[lengths]; (* find the maximum length if not already
known *)

Now use Count to find the frequency of each length up to the maxlength.

and so on.

To get them all at once, Map it across the range from 0 to maxlength.

Map[Count[lengths, #] &, Range[0, maxlength]]

Or better yet, generate a list of ordered pairs {n, frequency} like so.

Map[{#, Count[lengths, #]} &, Range[0, maxlength]]

Helen Read
University of Vermont

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.