[R] subsetting objects

Gabor Grothendieck ggrothendieck at myway.com
Thu Oct 9 23:08:51 CEST 2003



test <- data.frame(ID=c(1,1,1,2,2,2),data=1:6)
do.call("rbind", by(test,test$ID,function(x)x[2,]) )

 --- On Thu 10/09, Jean Eid < jeaneid at chass.utoronto.ca > wrote:
From: Jean Eid [mailto: jeaneid at chass.utoronto.ca]
To: r-help at stat.math.ethz.ch
Date: Thu, 9 Oct 2003 16:06:12 -0400
Subject: [R] subsetting objects

I want to be able to exctract a matrix from a data frame that contains repeated measurements for individuals. i.e I want to exctract the second observation for each individual in the study. <br>Is there a way of doing this? <br><br>I guess what I am trying to ask is if there as a multidimensional version of aggregate() as in aggregate(data, list(data[,"ID"]), function(x) x[2,])<br>but aggregate will only give back scalars. <br><br>Thank you, <br>Jean<br>	[[alternative HTML version deleted]]<br><br>______________________________________________<br>R-help at stat.math.ethz.ch mailing list<br>https://www.stat.math.ethz.ch/mailman/listinfo/r-help<br>

_______________________________________________
No banners. No pop-ups. No kidding.
Introducing My Way - http://www.myway.com




More information about the R-help mailing list