Skip to content
Prev 256216 / 398506 Next

random sampling with levels and with replacement

Hi,

I am not perfectly sure what you want to do, but here is what I would do 
to maintain good/bad ratio in the sample (as Daniel posted, split the 
data and sample from the groups):

df <- data.frame(V1 = 1:400, V2 = c(rep("good",360), rep("bad",40)))
isGood <- which(df$V2=="good")
isBad <- which(df$V2=="bad")
sampleGood <- df[sample(isGood, replace=TRUE),]
sampleBad <- df[sample(isBad, replace=TRUE),]
summary(rbind(sampleGood, sampleBad))

Please include a more specific example with test data (for "final" in 
this case) next time.

Best regards,

Andreas


taby gathoni schrieb: