title: Count number of alternations in a coin flip sequence
body: <p>I have a sequence of ones and zeros and I would like to count the number of alternations. e.g.</p>
  
  <pre><code>x &lt;- rbinom(10, 1, 1/2)
  &gt; x
   [1] 0 0 1 1 1 1 1 0 1 0
  </code></pre>
  
  <p>Thus I would like to count (in R) how many times the sequence alternates (or flips) from one to zero. In the above sequence the number of alternations (counted by hand) is 4.</p>