MathGroup Archive 2012

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

Search the Archive

Re: Integer Length Count

  • To: mathgroup at smc.vnet.net
  • Subject: [mg128773] Re: Integer Length Count
  • From: Helen Read <readhpr at gmail.com>
  • Date: Sat, 24 Nov 2012 02:29:47 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <k8nc79$dh1$1@smc.vnet.net>

On 11/23/2012 3:30 AM, sylviehobbs at comcast.net 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 
IntegerLength.

 From the Documentation:

IntegerLength[n]
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.

Count[lengths,0]
Count[lengths,1]
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






  • Prev by Date: How Can I Make A String Variable With Styled Text?
  • Next by Date: Re: correlation function
  • Previous by thread: Re: Integer Length Count
  • Next by thread: How Can I Make A String Variable With Styled Text?