title: randomly ordering across groups (not within group) in data.table
body: <p>Let's say I want to order the <code>iris</code> dataset (as a <code>data.table</code>) by Species, keeping observations grouped by species and randomly ordering across species. </p>
  
  <p>How do I do that?</p>
  
  <p>I am not talking about generating a random order within groups (species). </p>
  
  <p>My intuition was to write the code bellow. But it actually creates the within species random variable. Well at least it makes the question reproducible </p>
  
  <pre><code>d &lt;- iris %&gt;% data.table
  set.seed('12345')
  d[,g:=runif(.N),Species]
  </code></pre>