Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compute percentile for a given value

Tags:

r

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?

like image 991
this.is.not.a.nick Avatar asked Jul 09 '13 14:07

this.is.not.a.nick


People also ask

How percentile is calculated example?

Percentile Definition Percentile is defined as the value below which a given percentage falls under. For example, in a group of 20 children, Ben is the 4th tallest and 80% of the children are shorter than you. Hence, it means that Ben is at the 80th percentile.


1 Answers

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.

like image 166
semibruin Avatar answered Oct 09 '22 08:10

semibruin