Dear R-Experts, In a data simulation, I would like a balanced distribution with a nested structure for classroom and teacher (not for school). I mean 50 pupils belonging to C1, 50 other pupils belonging to C2, 50 other pupils belonging to C3 and so on. Then I want the 50 pupils belonging to C1 with T1, the 50 pupils belonging to C2 with T2, the 50 pupils belonging to C3 with T3 and so on. The school don?t have to be nested, I just want a balanced distribution, I mean 60 pupils in S1, 60 other pupils in S2 and so on. Here below the reproducible example. Many thanks for your help. ############## set.seed(123) ? # G?n?ration al?atoire des colonnes pupils<-1:300 ? classroom<-sample(c("C1","C2","C3","C4","C5","C6"),300,replace=T) ? teacher<-sample(c("T1","T2","T3","T4","T5","T6"),300,replace=T) ? school<-sample(c("S1","S2","S3","S4","S5"),300,replace=T) ? ? ##############
Wouldn't the students/teachers/schools be enumerated and the properties you are studying be random/correlated according to the enumerated values? On May 18, 2019 6:57:06 AM PDT, varin sacha via R-help <r-help at r-project.org> wrote:>Dear R-Experts, > >In a data simulation, I would like a balanced distribution with a >nested structure for classroom and teacher (not for school). I mean 50 >pupils belonging to C1, 50 other pupils belonging to C2, 50 other >pupils belonging to C3 and so on. Then I want the 50 pupils belonging >to C1 with T1, the 50 pupils belonging to C2 with T2, the 50 pupils >belonging to C3 with T3 and so on. The school don?t have to be nested, >I just want a balanced distribution, I mean 60 pupils in S1, 60 other >pupils in S2 and so on. >Here below the reproducible example. >Many thanks for your help. > >############## >set.seed(123) ? ># G?n?ration al?atoire des colonnes >pupils<-1:300 ? >classroom<-sample(c("C1","C2","C3","C4","C5","C6"),300,replace=T) ? >teacher<-sample(c("T1","T2","T3","T4","T5","T6"),300,replace=T) ? >school<-sample(c("S1","S2","S3","S4","S5"),300,replace=T) ? ? >############## > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >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.-- Sent from my phone. Please excuse my brevity.
Dear varin sacha, Not very sure what you want, but will the following help a little? tmp <- rep(c("C1","C2","C3","C4","C5","C6"), 50) # make a character vector, with 50 "C1", 50 "C2", ... classroom <- tmp[sample(1:300)] # make a random permutation. Certainly you may also make it into one line: classroom <- rep(c("C1","C2","C3","C4","C5","C6"), 50) [sample(1:30)] Best, Lei Chen On Sat, May 18, 2019 at 3:57 PM varin sacha via R-help <r-help at r-project.org> wrote:> > Dear R-Experts, > > In a data simulation, I would like a balanced distribution with a nested structure for classroom and teacher (not for school). I mean 50 pupils belonging to C1, 50 other pupils belonging to C2, 50 other pupils belonging to C3 and so on. Then I want the 50 pupils belonging to C1 with T1, the 50 pupils belonging to C2 with T2, the 50 pupils belonging to C3 with T3 and so on. The school don?t have to be nested, I just want a balanced distribution, I mean 60 pupils in S1, 60 other pupils in S2 and so on. > Here below the reproducible example. > Many thanks for your help. > > ############## > set.seed(123) > # G?n?ration al?atoire des colonnes > pupils<-1:300 > classroom<-sample(c("C1","C2","C3","C4","C5","C6"),300,replace=T) teacher<-sample(c("T1","T2","T3","T4","T5","T6"),300,replace=T) school<-sample(c("S1","S2","S3","S4","S5"),300,replace=T) > ############## > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
Many thanks Jeff and Linus, Yes to Jeff, OK with Linus but.... classroom <- rep(c("C1","C2","C3","C4","C5","C6"), 50) [sample(1:300)] how can I include the nested structure, I mean the teacher. Now, I would like the 50 pupils belonging to C1 with T1, the 50 pupils belonging to C2 with T2, the 50 pupils belonging to C3 with T3 and so on. Le samedi 18 mai 2019 ? 16:20:33 UTC+2, Linus Chen <linus.l.chen at gmail.com> a ?crit : Dear varin sacha, Not very sure what you want, but will the following help a little? tmp <- rep(c("C1","C2","C3","C4","C5","C6"), 50) # make a character vector, with 50 "C1", 50 "C2", ... classroom <- tmp[sample(1:300)] # make a random permutation. Certainly you may also make it into one line: classroom <- rep(c("C1","C2","C3","C4","C5","C6"), 50) [sample(1:30)] Best, Lei Chen On Sat, May 18, 2019 at 3:57 PM varin sacha via R-help <r-help at r-project.org> wrote:> > Dear R-Experts, > > In a data simulation, I would like a balanced distribution with a nested structure for classroom and teacher (not for school). I mean 50 pupils belonging to C1, 50 other pupils belonging to C2, 50 other pupils belonging to C3 and so on. Then I want the 50 pupils belonging to C1 with T1, the 50 pupils belonging to C2 with T2, the 50 pupils belonging to C3 with T3 and so on. The school don?t have to be nested, I just want a balanced distribution, I mean 60 pupils in S1, 60 other pupils in S2 and so on. > Here below the reproducible example. > Many thanks for your help. > > ############## > set.seed(123) > # G?n?ration al?atoire des colonnes > pupils<-1:300 > classroom<-sample(c("C1","C2","C3","C4","C5","C6"),300,replace=T)? teacher<-sample(c("T1","T2","T3","T4","T5","T6"),300,replace=T)? school<-sample(c("S1","S2","S3","S4","S5"),300,replace=T)> ############## > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
Can you build your data top-down? schools <- paste("s", 1:6, sep="") classes <- character() for (school in schools) { classes <- c(classes, paste(school, paste("c", 1:5, sep=""), sep = ".")) } pupils <- character() for (class in classes) { pupils <- c(pupils, paste(class, paste("p", 1:10, sep=""), sep = ".")) } B.> On 2019-05-18, at 09:57, varin sacha via R-help <r-help at r-project.org> wrote: > > Dear R-Experts, > > In a data simulation, I would like a balanced distribution with a nested structure for classroom and teacher (not for school). I mean 50 pupils belonging to C1, 50 other pupils belonging to C2, 50 other pupils belonging to C3 and so on. Then I want the 50 pupils belonging to C1 with T1, the 50 pupils belonging to C2 with T2, the 50 pupils belonging to C3 with T3 and so on. The school don?t have to be nested, I just want a balanced distribution, I mean 60 pupils in S1, 60 other pupils in S2 and so on. > Here below the reproducible example. > Many thanks for your help. > > ############## > set.seed(123) > # G?n?ration al?atoire des colonnes > pupils<-1:300 > classroom<-sample(c("C1","C2","C3","C4","C5","C6"),300,replace=T) teacher<-sample(c("T1","T2","T3","T4","T5","T6"),300,replace=T) school<-sample(c("S1","S2","S3","S4","S5"),300,replace=T) > ############## > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
Dear Boris, Yes, top-down, no problem. Many thanks, but in your code did you not forget "teacher" ? As a reminder teacher has to be nested with classes. I mean the 50 pupils belonging to C1 must be with (teacher 1) T1, the 50 pupils belonging to C2 with T2, the 50 pupils belonging to C3 with T3 and so on. Best, Le samedi 18 mai 2019 ? 16:52:48 UTC+2, Boris Steipe <boris.steipe at utoronto.ca> a ?crit : Can you build your data top-down? schools <- paste("s", 1:6, sep="") classes <- character() for (school in schools) { ? classes <- c(classes, paste(school, paste("c", 1:5, sep=""), sep = ".")) } pupils <- character() for (class in classes) { ? pupils <- c(pupils, paste(class, paste("p", 1:10, sep=""), sep = ".")) } B.> On 2019-05-18, at 09:57, varin sacha via R-help <r-help at r-project.org> wrote: > > Dear R-Experts, > > In a data simulation, I would like a balanced distribution with a nested structure for classroom and teacher (not for school). I mean 50 pupils belonging to C1, 50 other pupils belonging to C2, 50 other pupils belonging to C3 and so on. Then I want the 50 pupils belonging to C1 with T1, the 50 pupils belonging to C2 with T2, the 50 pupils belonging to C3 with T3 and so on. The school don?t have to be nested, I just want a balanced distribution, I mean 60 pupils in S1, 60 other pupils in S2 and so on. > Here below the reproducible example. > Many thanks for your help. > > ############## > set.seed(123)? > # G?n?ration al?atoire des colonnes > pupils<-1:300? > classroom<-sample(c("C1","C2","C3","C4","C5","C6"),300,replace=T)? teacher<-sample(c("T1","T2","T3","T4","T5","T6"),300,replace=T)? school<-sample(c("S1","S2","S3","S4","S5"),300,replace=T)? ?> ############## > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.