title: How to sort data.frame by columns with strings containing different number of digits?
body: <p>I would like to sort a df like this one:</p>
  <pre class="lang-r prettyprint-override"><code>library(dplyr)
  tags &lt;- c(&quot;F23-F45&quot;, &quot;A69-1008-1&quot;, &quot;A69-1008-10&quot;, &quot;A69-1008-10&quot;, &quot;A69-1008-100&quot;, &quot;A69-1008-12&quot;)
  animal_names &lt;- c(&quot;Dim&quot;,&quot;Dami&quot;, &quot;Pet&quot;, &quot;Nic&quot;, &quot;Li&quot;, &quot;Tan&quot;)
  
  df &lt;- tibble(tag = tags, animal_name = animal_names)
  # A tibble: 6 x 2
    tag          animal_name
    &lt;chr&gt;        &lt;chr&gt;      
  1 F23-F45      Dim        
  2 A69-1008-1   Dami       
  3 A69-1008-10  Pet        
  4 A69-1008-10  Nic        
  5 A69-1008-100 Li         
  6 A69-1008-12  Tan
  </code></pre>
  <p>I would like to sort first by <code>tag</code> and then by <code>animal_name</code>. Typically I do it with <code>arrange()</code>function of dplyr package. It would result in this df:</p>
  <pre class="lang-r prettyprint-override"><code>&gt; df %&gt;% arrange(tag, animal_name)
  # A tibble: 6 x 2
    tag          animal_name
    &lt;chr&gt;        &lt;chr&gt;      
  1 A69-1008-1   Dami       
  2 A69-1008-10  Nic        
  3 A69-1008-10  Pet        
  4 A69-1008-100 Li         
  5 A69-1008-12  Tan        
  6 F23-F45      Dim        
  </code></pre>
  <p>However, I would like to apply a kind of numeric sort so that <code>A69-1008-12</code> occurrs <strong>before</strong> <code>A69-1008-100</code>. This problem has been solved for a vector already (see <a href="https://stackoverflow.com/questions/17531403/how-to-sort-a-character-vector-where-elements-contain-letters-and-numbers-in-r">this question</a>) but I wonder how to transfer it to data.frames?</p>