Hi Robert,
Try
set.seed(123)
x <- seq(100)
x <- sample(x, 1000, replace = TRUE)
f <- ecdf(x)
f(10)
# [1] 0.099
f(71)
# [1] 0.716
See ?ecdf for more information.
HTH,
Jorge.-
On Tue, Jan 10, 2012 at 11:52 PM, Robert A'gata <> wrote:
Hello,
I am not sure how to do this in R. Any suggestion would be
appreciated. I have a vector of values from where I build an empirical
CDF. For example:
x <- seq(1,100)
x <- sample(x,1000,replace=T)
quantile(x,probs=seq(0,1,.05))
? ?0% ? ? 5% ? ?10% ? ?15% ? ?20% ? ?25% ? ?30% ? ?35% ? ?40% ? ?45%
?50% ? ?55%
?1.00 ? 5.00 ?10.00 ?16.00 ?20.00 ?25.00 ?31.00 ?36.00 ?41.00 ?45.55
50.00 ?56.00
? 60% ? ?65% ? ?70% ? ?75% ? ?80% ? ?85% ? ?90% ? ?95% ? 100%
?60.00 ?65.00 ?70.00 ?74.00 ?80.00 ?85.00 ?91.00 ?95.05 100.00
I would like to write a function that takes in a number z and vector x
(i.e. the raw vector).It returns percentile of z wrt x. E.g.
Should return something around 0.708 or 0.709. I am wondering if there
is any pre-packaged functions that do this in R? If not, how can I
write such a function. Any suggestion would be appreciated.
Robert