[R-sig-ME] School Sampling
Roberts, Kyle
kyler at mail.smu.edu
Wed Jan 14 19:12:09 CET 2009
Thanks to Daniel for this great solution!
> new<-data.frame()
> for (i in school.sample)
+ new <- rbind(new,z[z$school==i,])
> new
school score
9 5 29
10 5 30
91 5 29
101 5 30
7 4 27
8 4 28
*********************************************************
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: r-sig-mixed-models-bounces at r-project.org [mailto:r-sig-mixed-models-bounces at r-project.org] On Behalf Of Roberts, Kyle
Sent: Wednesday, January 14, 2009 12:02 PM
To: 'Daniel Ezra Johnson'
Cc: r-sig-mixed-models at r-project.org
Subject: Re: [R-sig-ME] 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?
_______________________________________________
R-sig-mixed-models at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
More information about the R-sig-mixed-models
mailing list