This question is an extension to the StackOverflow question asked and answered here.
My circumstances are different in that I want to calculate the percentile of each value within a vector of 50,000 (or more!) values. For example --
df <- data.frame(val = rnorm(n = 50000, mean = 50, sd = 20))
df$val.percentile <- sapply(X = df$val, function(x) ecdf(df$val)(x))
head(df)
Is there a good way to optimize the process for calculating the percentile for each value? Essentially I'd like to make it as efficient as possible so the run time is as small as possible.