Percentile for Each Observation w/r/t Grouping Variable
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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. 回答1: 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))) 回答2: Using