Given the following data
set.seed(123)
id <- data.frame(id=seq(1:100))
df <- data.frame(id,
lef=(sample(27:65,nrow(id), replace = TRUE)),
tra=(sample(1:5,nrow(id), replace = TRUE)),
ab=(sample(c("A", "B"),nrow(id), replace = TRUE)),
zxc=(sample(c("Z", "X", "C"),nrow(id), replace = TRUE)))
I want a (random?) selection out of df that leads to:
- 4 groups with a size of exact 10 each (Group 1 n=10; G2 n=10 ….)
- Replacement is not allowed (unique id within and between the groups)
- the 4 groups must contain all the columns (G1= 5x10; G2 = 5X10…..)
- the 4 groups “must” have equal means on ‘lef’ (meanG1=meanG2=…)and equal proportions on ‘ab’ (Pa1=Pa2…; Pb1=Pb2….), ‘tra’ and ‘zxc’, or result in the most optimal solution given df.
I have looked over the internet but could not find a solution, this could be a problem using incorrect keys (knapsack, matching algorithm).
I hope someone can help,
Thank you.
Aucun commentaire:
Enregistrer un commentaire