title: Stratified sample when some strata are too small
body: <p>I need to draw a stratified sample with <code>n</code> observation in each stratum, but some strata have fewer observations than <code>n</code>. If a stratum has too few observations (say, <code>k&lt;n</code> observations), I want to sample all <code>k</code> observations from that stratum.</p>
  
  <pre><code>require(sampling)
  
  n &lt;- 10
  geo_ID &lt;- c(rep(1, times = 20), rep(2, times = 20), rep(c(1, 2, 3, 4), times = 5))
      set.seed(42)
  V1 &lt;- rnorm(60, 0, 1)
  V2 &lt;- rnorm(60, 2, 1)
  
  DF &lt;- data.frame(geo_ID = geo_ID, V1 = V1, V2 = V2)
      #Sort as explained in ?strata help file
  DF &lt;- DF[order(DF[, "geo_ID"]), ]
  
  strata(DF, stratanames = "geo_ID", size = c(n, n, n, n), method = "srswor")
  </code></pre>
  
  <p>If I use sampling without replacement as above, I (understandably) get the error:</p>
  
  <pre><code>Error in strata(DF, stratanames = "geo_ID", size = c(10, 10, 10, 10),  : 
    not enough obervations in the stratum 
  </code></pre>
  
  <p>Sampling with replacement avoids the error, <code>method = "srswr"</code>, but that's not ideal since it sometimes draws repeats for strata that are sufficiently large to have only unique sample draws.</p>
  
  <p>NOTE: There's a similar question on SO but it wasn't really answered. Also I think this question is more general. (<a href="https://stackoverflow.com/questions/7268963/stratified-sampling-not-enough-observations">Stratified sampling - not enough observations</a>) The answers to the linked question are not generally useful since they require either (i) sample sizes proportional  to the stratum size (whereas, I need a fixed number) or (ii) manually programming stratum-by-stratum, which isn't feasible as the number of strata increases.</p>