On Tue, Sep 29, 2009 at 6:58 AM, <xavier.char...@free.fr> wrote: > Apologies for the misunderstanding. I can come up with a solution that might > suit your needs: > > library(plyr) > out <- ddply(test, .(nr), function(x) data.frame(date=x$date, > index=rank(-as.integer(x$date)))) > out[is.na(out$nr) | is.na(out$date), "index"] <- NA
That code can be simplified a little to: ddply(test, .(nr), transform, index = rank(-as.integer(date), na.last = "keep")) Hadley -- 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.