this.is.not.a.nick
this.is.not.a.nick

Reputation: 2701

Compute percentile for a given value

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?

Upvotes: 5

Views: 8235

Answers (1)

semibruin
semibruin

Reputation: 1013

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.

Upvotes: 13

Related Questions