2

Is there any function in R that will select equal number of units from every level of a variable? For example I have a data set consisting of a variable called "taste" and there are three levels of the variable taste say "bad", "normal" and "good". Now I want to select a sample which draws equal number of units from each level of the taste variable. How can I select such a sample in R?

Rini
  • 35
  • 8
  • Please have a look at [How to make a great R reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so it is easy for others to help you. – Ronak Shah Jan 16 '17 at 11:45

1 Answers1

2

We can do with rep and sample

sample(rep(unique(data$taste), each = 25))
akrun
  • 874,273
  • 37
  • 540
  • 662