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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With