title: find range hi/low by grouping values if they are separated by less than 3 positions
body: <p>My data consists of 4 columns: date, low, high, and position.  </p>
  
  <p>I am trying to find the ranges by summarizing the data into groups based on the position field. </p>
  
  <ol>
  <li>If diff(position) &lt; 3, then group the data together and apply the range function to each group. </li>
  <li>If diff(position) >= 3 calculate range on the current point and the previous one only.</li>
  </ol>
  
  <p>An example of the first 15 positions, the 4th field of the data:</p>
  
  <pre><code>c(12,14,17,18,19,20,21,22,24,28,33,36,37,38,43)
  </code></pre>
  
  <p>and the expected outcome is to group <code>(12,14)</code> then <code>(17:24)</code>, <code>(24,28)</code>, <code>(28,33)</code>, <code>(33,36)</code>, <code>(36:38)</code>, and finally <code>(38,43)</code> and find the range for each of the groups.</p>