Percentile for Each Observation w/r/t Grouping Variable

r

Solution

Following up on Vince's solution, you can also do this with `plyr` or `by`:

ddply(df, .(years), function(x) transform(x, percentile=ecdf(x$scores)(x$scores)))

Problem

I have some data that looks like the following. It is grouped by variable "Year" and I want to extract the percentiles of each observation of Score, with respect to the Year it is from, preferably as a vector. ``` Year Score 2001 89 2001 70 2001 72 2001 ... .......... 2004 87 2004 90 ``` etc. How can I do this? aggregate will not work, and I do not think apply will work either.

Original source