title: How to sort a data frame by user-defined (e.g. non-alphabetic order)
body: <p>Given a data frame <code>dna</code></p>
  
  <pre><code>&gt; dna
  chrom   start
  chr2    39482
  chr1    203918
  chr1    198282
  chrX    7839028
  chr17   3874
  </code></pre>
  
  <p>The following code reorders <code>dna</code> by <code>$chrom</code> in alphabetical ascending order and by <code>$start</code> in numerical ascending order:</p>
  
  <pre><code>&gt; dna &lt;- dna[with(dna, order(chrom, start)), ]
  &gt; dna
  chrom   start
  chr1    198282
  chr1    203918
  chr17   3874
  chr2    39482
  chrX    7839028
  </code></pre>
  
  <p>However, I would like to be able to have <code>$chrom</code> ordered as follows (simplified for the sake of my example here):</p>
  
  <pre><code>chrom_order &lt;- c("chr1","chr2", "chr17", "chrX")
  </code></pre>
  
  <p>I am not allowed to rename stuff, for example <code>chr1</code> to <code>chr01</code>.</p>