How to calculate cumulative distribution in R? I need to calculate the cumulative distribution function of a data sample. 
Is there something similar to hist() in R that measure the cumulative density function?
I have tries ecdf()  but i can't understand the logic.
 A: The ecdf function applied to a data sample returns a function representing the empirical cumulative distribution function. For example:
> X = rnorm(100) # X is a sample of 100 normally distributed random variables
> P = ecdf(X)    # P is a function giving the empirical CDF of X
> P(0.0)         # This returns the empirical CDF at zero (should be close to 0.5)
[1] 0.52
> plot(P)        # Draws a plot of the empirical CDF (see below)


If you want to have an object representing the empirical CDF evaluated at specific values (rather than as a function object) then you can do
> z = seq(-3, 3, by=0.01) # The values at which we want to evaluate the empirical CDF
> p = P(z)                # p now stores the empirical CDF evaluated at the values in z

Note that p contains at most the same amount of information as P (and possibly it contains less) which in turn contains the same amount of information as X.
A: What you appear to need is this to get the acumulated distribution (probability of get a value <= than x on a sample), ecdf returns you a function, but it appears to be made for plotting, and so, the argument of that function, if it were a stair, would be the index of the tread.
You can use this:
acumulated.distrib= function(sample,x){
    minors= 0
    for(n in sample){
        if(n<=x){
            minors= minors+1
        }
    }
    return (minors/length(sample))
}

mysample = rnorm(100)
acumulated.distrib(mysample,1.21) #1.21 or any other value you want.

Sadly the use of this function is not very fast.
I don't know if R has a function that does this returning you a function, that would be more efficient.
A: friend, you can read the code on this blog.
sample.data = read.table ('data.txt', header = TRUE, sep = "\t")
cdf <- ggplot (data=sample.data, aes(x=Delay, group =Type, color = Type)) + stat_ecdf()
cdf

more details can be found on following link:
r cdf and histogram
