title: Radix sort implementation in R
body: <p>How do you implement <a href="https://en.wikipedia.org/wiki/Radix_sort" rel="nofollow">Radix sort</a> in base R (e.g.) for the following vector:</p>
  
  <pre><code>vec &lt;- c(25, 478, 34, 9021, 6, 9947, 504, 22)
  </code></pre>
  
  <p>In summary, Radix sort does the following: </p>
  
  <ul>
  <li>Sort based on <code>unit</code> positions:
  <code>9021   22   34  504   25    6 9947  478</code></li>
  <li>Sort based on <code>ten</code> positions:
  <code>504    6 9021   22   25   34 9947  478</code></li>
  <li>Sort based on <code>hundred</code> positions:
  <code>6 9021   22   25   34  478  504 9947</code></li>
  <li>Sort based on <code>thousand</code> positions:
  <code>6   22   25   34  478  504 9021 9947</code></li>
  </ul>
  
  <p>and so on. Of course, <code>vec</code> is just an example and the solution is able to deal with data of any length containing numbers of any length.</p>
  
  <p>The output would be <code>vec</code> sorted ascending (or descending). That is,</p>
  
  <pre><code>6   22   25   34  478  504 9021 9947
  </code></pre>