It sounds like you are interested in taking a random stratified sample. You could do this using the stratsample()
function from the survey
package.
In the example below, I create some fake data to mimic what you have, then I define a function to take a random proportional stratified random sample, then I apply the function to the fake data.
# example data
ndf <- 1000
df <- data.frame(ID=sample(ndf), Name=sample(ndf),
Campaign=sample(c("D2D", "F2F", "TM", "WW"), ndf, prob=c(0.25, 0.38, 0.17, 0.21), replace=TRUE),
Gender=sample(c("Male", "Female"), ndf, prob=c(0.54, 0.46), replace=TRUE))
# function to take a random proportional stratified sample of size n
rpss <- function(stratum, n) {
props <- table(stratum)/length(stratum)
nstrat <- as.vector(round(n*props))
nstrat[nstrat==0] <- 1
names(nstrat) <- names(props)
stratsample(stratum, nstrat)
}
# take a random proportional stratified sample of size 10
selrows <- rpss(stratum=interaction(df$Campaign, df$Gender, drop=TRUE), n=10)
df[selrows, ]