title: nested sampling of a data.frame in R
body: <p>In data.frame <code>p</code> below, there are <code>757</code> unique district names (<code>dname</code>) &amp; <code>5210</code> unique school names (<code>sname</code>).</p>
  <p>I was wondering how to sample 126 <code>sname</code>s (schools) from 40 <code>dname</code>s (districts) in R?</p>
  <p>So, in the final sample (say <code>X</code>), <code>dim(table(X$dname, X$sname))</code> must return: <code>&gt; [1] 40 126</code></p>
  <p>In a sense, this is <code>multi-stage sampling</code>, so I'm open to any packages.</p>
  <pre><code>p &lt;- read.csv(&quot;https://raw.githubusercontent.com/hkil/m/master/a.csv&quot;)
  </code></pre>