Re: [S] Looping

Prof Brian D Ripley (
Fri, 21 Aug 1998 09:41:00 +0100 (BST)

On Fri, 21 Aug 1998, Lars Karlsson wrote:

> Is there a way to avoid the loops below?
> vec is a vector of length n. I want to count the number of instances
> where an element and the next j-th element both equals 1.

This is up to scaling the non-centred acf of the vector vec==1. So you
should be able to adapt the output of acf() for your purpose. That uses
Fortran for the loops.

[ completely different solution clipped ]

Brian D. Ripley,        
Professor of Applied Statistics,
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

----------------------------------------------------------------------- This message was distributed by To unsubscribe send e-mail to with the BODY of the message: unsubscribe s-news