title: How to resample data by clusters (block sampling) with replacement in R using Sampling package
body: <p>This is my dummy data:</p>
  
  <pre><code>income &lt;- as.data.frame.vector &lt;- sample(1000:10000, 1000, replace=TRUE)
  individuals &lt;- as.data.frame.vector &lt;- sample(1:50,1000,replace=TRUE)
  datatest &lt;- as.data.frame (cbind (income, individuals))
  </code></pre>
  
  <p>I know I can sample by individual rows with this code: </p>
  
  <pre><code>sample &lt;- datatest[sample(nrow(datatest), replace=TRUE),]
  </code></pre>
  
  <p>Now, I want to extract random samples with replacement and equal probabilities of the dataset but sampling complete blocks of observations with the same individual code.
  Note that there are 50 individuals, but 1000 observations. Some observations belong to the same individual, so I want to sample by individuals (clusters, in this case), not observations. I don't mind if the extracted samples differ slightly in the number of observations. How can I do that? </p>
  
  <p>I have tried: </p>
  
  <pre><code> library(sampling)
   samplecluster &lt;- cluster (datatest, clustername=c("individuals"), size=50,
                             method="srswr")
  </code></pre>
  
  <p>But the outcome is not the sampled data. Am I missing something?</p>