On 5/7/06, Alexander Nervedi <[EMAIL PROTECTED]> wrote: > Hi > > is there an R equivalent of the Stata collpase command? > > suppose i have: > > classes <- 1:5 > schools <- letters[1:5] > stud <- 1:10 > > dat <- expand.grid(School = schools, Grade = classes, Student.ID = stud) > with(dat, table(Student.ID, School)) > dat$marks <- rnorm(nrow(dat), 50, 25) > > > I want to get the mean score by school and class while the data is at the > school-class-student level. I could write something up but I was wondering > if there is already something otu there. >
library(doBy) summaryBy(marks ~ School + Grade, dat) # by school/Grade combo # or library(Hmisc) with(dat, summarize(marks, dat[,1:2], mean)) # same # or (not quite the same) library(Hmisc) summary(marks ~ School + Grade, dat) # by School and separately by Grade Also see ?tapply, ?by, colMeans? ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html