Skip to content
Prev 365930 / 398502 Next

how to randomly select the samples with different probabilities for different classes?

Hi Marna,
If we assume a sample size of 1, something like this:

dat[sample(which(dat$group!="C"),ceiling(14*0.4),TRUE),]
dat[sample(which(dat$group=="C"),floor(14*0.6),TRUE),]

Then just step through the two subsets to access your samples.

One problem is that you will not get exactly 40 or 60 %, which is why
I had to put the "ceiling " and "floor" functions to work. Also, you
will have to sample with replacement as you will exhaust the "C"
group.

Jim
On Wed, Dec 7, 2016 at 10:58 PM, Marna Wagley <marna.wagley at gmail.com> wrote: