On Thu, Jul 15, 2010 at 11:08 PM, Dennis Murphy <djmu...@gmail.com> wrote: > Hi: > > I sincerely hope there's an easier way, but one method to get this is as > follows, > with d as the data frame name of your test data: > > d <- d[order(with(d, Age, School, rev(Grade))), ] > d$Count <- do.call(c, mapply(seq, 1, as.vector(t(with(d, table(Age, > School))))))
It's easier if you use plyr ;) library(plyr) ddply(d, c("Age", "School"), transform, school_count = seq_along(ID)) Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ ______________________________________________ R-help@r-project.org mailing list 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.