MathGroup Archive 2004

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

Search the Archive

Re: Counting Runs


Gregory Lypny wrote:
> 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
> 	v={1,1,1,-1,1,1,1,1,1,-1,-1,-1,-1,1}.
> 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.
> 
> 	Greg
> 
Please forgive me. First I had another way to solve your problem in 
mind. Of course it's sufficient to define

countruns[data_, items_] :=
   Count[Split[data], {x__} /; x == #] & /@ items

-- 
Peter Pein
Berlin


  • Prev by Date: Re: foreach loop
  • Next by Date: Re: Re: Garbage collection problem
  • Previous by thread: Re: Counting Runs
  • Next by thread: Re: Counting Runs