MathGroup Archive 2004

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

Search the Archive

Re: Counting Runs

  • To: mathgroup at
  • Subject: [mg51946] Re: [mg51890] Counting Runs
  • From: "David Park" <djmp at>
  • Date: Fri, 5 Nov 2004 02:18:50 -0500 (EST)
  • Sender: owner-wri-mathgroup at


Here is a method in some detail.

data = {1, 1, 1, -1, 1, 1, 1, 1, 1, -1, -1, -1, -1, 1};

Print["Split data into runs"]
Print["Extract the first element of each run"]
First /@ %%
Print["Sort and split the runs of each element"]
Print["Print the results"]
Print["Number of runs of ", First[#], " is ", Length[#]] & /@ %%;

David Park
djmp at 

From: Gregory Lypny [mailto:gregory.lypny at]
To: mathgroup at

Looking for an elegant way to count runs to numbers in a series.  
Suppose I have a list of ones and negative ones such as
I'd like to create a function that counts the number of runs of 1s and 
-1s, which in this case is 3 and 2.


  • Prev by Date: Re: Plotting scattergram
  • Next by Date: Re: foreach loop
  • Previous by thread: Re: Counting Runs
  • Next by thread: Re: Re: Counting Runs