Compute percentile for a given value

r

Solution

Let `x` be the data.frame, and let `x$score` be the column of the total score. You could add a column of percentile by

x$percentile <- ecdf(x$score)(x$score)

Now the data.frame `x` has an additional column `percentile`, which is what you want.

Problem

In a dataframe I have a column with the total score on a questionnaire. I want to add a column in which, for each total score, there is the relative percentile with respect to the data distribution. How can I do it in R?

Original source