title: Group a vector of numbers by range
body: <p>I have a sorted vector:</p>
  <pre><code>c(1, 10, 31, 80, 100, 120, 160)
  </code></pre>
  <p>I would like to split its elements into several groups by range, which I set to 31 in this example.</p>
  <p>The result is like this:</p>
  <pre><code>[[1]] 1, 10, 31
  [[2]] 80, 100
  [[3]] 100, 120
  [[4]] 160
  </code></pre>
  <p>The ranges in each group is less than 31. I have tried a loop, but I do not like it. Also, I tried the <code>outer</code> function, where I calculated all pairwise differences:</p>
  <pre><code>res &lt;- outer(vec, vec, &quot;-&quot;)
  </code></pre>
  <p>Then filter each column by the condition <code>&gt; 0</code> and <code>&lt; 31</code>.</p>
  <pre><code>apply(res, 2, function(x) x[x &gt; 0 &amp; x &lt; 31])
  </code></pre>
  <p>The result is not good enough though...</p>