School Sampling
Yes, but it doesn't work when schools are sampled more than once. For example:
z<-data.frame(school=factor(rep(1:5, each=2)), score=21:30) school.sample<-sample(levels(z$school), 3, replace=T) school.sample
[1] "5" "5" "4"
new<-subset(z, school%in%school.sample) new
school score 7 4 27 8 4 28 9 5 29 10 5 30 ********************************************************* Dr. J. Kyle Roberts Department of Teaching and Learning Annette Caldwell Simmons School of Education and Human Development Southern Methodist University P.O. Box 750381 Dallas, TX? 75275 214-768-4494 http://www.hlm-online.com/ ********************************************************* -----Original Message----- From: Daniel Ezra Johnson [mailto:danielezrajohnson at gmail.com] Sent: Wednesday, January 14, 2009 12:00 PM To: Roberts, Kyle Cc: r-sig-mixed-models at r-project.org Subject: Re: [R-sig-ME] School Sampling
z<-data.frame(school=factor(rep(1:5, each=2)), score=21:30) school.sample<-sample(levels(z$school), 3, replace=T) school.sample
[1] "5" "1" "2"
new<-subset(z, school==school.sample)
Warning messages: 1: In is.na(e1) | is.na(e2) : longer object length is not a multiple of shorter object length 2: In `==.default`(school, school.sample) : longer object length is not a multiple of shorter object length
is it
new <- subset(z,school%in%school.sample)
that gives you the result you want?