Skip to content
Prev 6020 / 7420 Next

Calculating percentile rank of sample dataset compared to reference dataset in R

Hi,

sapply(c("iron", "nitrate"), function(x) round(approx(y =
1:nrow(df_ref), x = df_ref[, x], xout = df_sample[, x])$y/10))

should do the trick with base R:::approx() as workhorse.

You need to replace the /10 by a value corresponding to the length of
your reference database (e.g. if there are 500 rows only, divide by 5)

The results differs slightly from the solution of Akos by assigning a
value of 0.2651 to percentile rank 27 instead of 26.


Cheers!
On Thu, 22 Aug 2019 at 08:29, Glatthorn, Jonas <jglatth at gwdg.de> wrote: