Hi I have a data set which is like this: Data ID Type 1 A 2 B 3 A 4 A 5 A 6 B 7 B 8 A 9 B 10 B As you can see, there are 5 A and 5 B. Now, I want to a randomization of the data set which will assign 5 ID to a new group called "Set1" and and the other 5 to "Set2" The Set1 and Set2 will be either: Set1 (A A A B B ) and Set2 (A A B B B) or Set1(A A B B B) and Set2 (A A A B B). Each new group need to have at two A and two B, and one more B or A. Except this condition, everything else (ID, permutation, selection to Set1 and Set2) need to be random. Can anyone show me how to do the randomization? -- View this message in context: http://www.nabble.com/Conditional-randomization-of-groups-tp24854783p24854783.html Sent from the R help mailing list archive at Nabble.com.
Meyners, Michael, LAUSANNE, AppliedMathematics
2009-Aug-07 07:56 UTC
[R] Conditional randomization of groups
Hi "unknown", As a quick patch, try something like mydata$Set <- 1 mydata$Set[c(sample(mydata$ID[mydata$Type=="A"], ifelse(runif(1)<1/2,2,3)), sample(mydata$ID[mydata$Type=="B"], 3) )[1:5] ] <- 2 HTH, Michael -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of yabado Sent: Donnerstag, 6. August 2009 23:29 To: r-help at r-project.org Subject: [R] Conditional randomization of groups Hi I have a data set which is like this: Data ID Type 1 A 2 B 3 A 4 A 5 A 6 B 7 B 8 A 9 B 10 B As you can see, there are 5 A and 5 B. Now, I want to a randomization of the data set which will assign 5 ID to a new group called "Set1" and and the other 5 to "Set2" The Set1 and Set2 will be either: Set1 (A A A B B ) and Set2 (A A B B B) or Set1(A A B B B) and Set2 (A A A B B). Each new group need to have at two A and two B, and one more B or A. Except this condition, everything else (ID, permutation, selection to Set1 and Set2) need to be random. Can anyone show me how to do the randomization? -- View this message in context: http://www.nabble.com/Conditional-randomization-of-groups-tp24854783p248 54783.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.