title: How to create a stratified sample by state in R
body: <p>How can I create a stratified sample in R using the "sampling" package? My dataset has 355,000 observations. The code works fine up to the last line. Below is the code I wrote, but I always get the following message: "Error in sort.list(y) : 'x' must be atomic for 'sort.list' Have you called 'sort' on a list?"</p>
  
  <p>Please do not point me to older messages on Stackoverflow. I researched them, but have not been able to use them. Thank you.</p>
  
  <pre><code>## lpdata file has 355,000 observations
  # Exclude Puerto Rico, Virgin Islands and Guam
  sub.lpdata&lt;-subset(lpdata,"STATE" != 'PR' | "STATE" != 'VI' | "STATE" != 'GU')
  
  ## Create a 10% sample, stratified by STATE
  sort.lpdata&lt;-sub.lpdata[order(sub.lpdata$STATE),]
  tab.state&lt;-data.frame(table(sort.lpdata$STATE))
  size.strata&lt;-as.vector(round(ceiling(tab.state$Freq)*0.1))
  
  s&lt;-strata(sort.lpdata,stratanames=sort.lpdata$STATE,size=size.strata,method="srswor")}
  </code></pre>