Percentile for Each Observation w/r/t Grouping Variable

后端 未结 7 1360
广开言路
广开言路 2021-02-06 10:39

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 t

7条回答
  •  面向向阳花
    2021-02-06 11:10

    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)))
    

提交回复
热议问题