1

I am wondering would anyone have any sample code in order to be able to carry out "Quota Sampling" in R?

Thanks in advance!

Update with example dataset: enter image description here

For example I will need the following

  • 5 Abnormal, Occurring on a Wednesday, with Humidity equal to 24
  • 3 normal, Occurring on a Workday, with Humidity less than 24
Jay1995
  • 137
  • 1
  • 14
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. What exactly are your requirements? – MrFlick Oct 21 '20 at 21:03
  • updated with example data and example quotas – Jay1995 Oct 21 '20 at 21:21
  • 1
    This link may help: https://homerhanumat.github.io/elemStats/sampling-and-surveys.html#types-of-samples – Tou Mou Oct 21 '20 at 21:29

2 Answers2

1

Something like the following may reply to your question :

question1_data=subset(your_data,label==Abnormal & Day=="Wednesday" & Humidity==24)
sample_1=popsamp(5,question1_data)

question2_data=subset(your_data,label==normal & Day=="Workday" & Humidity<24)
sample_2=popsamp(3,question2_data)
Tou Mou
  • 1,270
  • 5
  • 16
  • question1_data part where it is meant to subset is not sub-setting the data? – Jay1995 Oct 21 '20 at 21:43
  • Plz look at the link in previous comment , stratified and cluster sampling approaches are explained there. As you didn't provided reproducible example , i can't reply to your question – Tou Mou Oct 21 '20 at 21:46
  • 1
    apologies, got it working with the above code. Thanks! – Jay1995 Oct 21 '20 at 21:50
  • If popsamp() doesn't work , use the sample() function instead. You could set the parameter Replace=TRUE/FALSE – Tou Mou Oct 21 '20 at 21:53
0

The popsamp() function is a function of tigerstats package :

set.seed(1837)
require(tigerstats)
str(iris)
quest_1=subset(iris,Species=="setosa") #selecting a sub group of data
quest_1
x=popsamp(4,quest_1)  # sampling in that group 
x # printing sample 
Tou Mou
  • 1,270
  • 5
  • 16