Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

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

Search the Archive

Re: Integer Length Count

  • To: mathgroup at smc.vnet.net
  • Subject: [mg128759] Re: Integer Length Count
  • From: Bob Hanlon <hanlonr357 at gmail.com>
  • Date: Sat, 24 Nov 2012 02:25:06 -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: <20121123082854.1CF386932@smc.vnet.net>

Conversion of integers to strings is not necessary and slows down the process.

n = 1000000;

data = RandomInteger[10000000, n];

t1 = Timing[lengthFrequency = Tally[Length /@ IntegerDigits[data]]][[1]]

2.12561

t2 = Timing[lengthFrequency2 = Tally[StringLength[ToString /@ data]]][[1]]

3.63404

Both processes provide the same results.

lengthFrequency == lengthFrequency2

True

Conversion to strings is much slower.

t2/t1

1.70965


Bob Hanlon


On Fri, Nov 23, 2012 at 3:28 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.
>
>
>
> Sylvia Hobbs
>



  • Prev by Date: Re: correlation function
  • Next by Date: Re: Is there way to use something like Assuming with the
  • Previous by thread: Integer Length Count
  • Next by thread: Re: Integer Length Count