How to Extract eCDF Values from the ecdf() Function in R (Example Code)
In this R tutorial you’ll learn how to get eCDF data from the ecdf() function.
Creation of Example Data
data(iris) # Loading example data head(iris) # Sepal.Length Sepal.Width Petal.Length Petal.Width Species # 1 5.1 3.5 1.4 0.2 setosa # 2 4.9 3.0 1.4 0.2 setosa # 3 4.7 3.2 1.3 0.2 setosa # 4 4.6 3.1 1.5 0.2 setosa # 5 5.0 3.6 1.4 0.2 setosa # 6 5.4 3.9 1.7 0.4 setosa |
data(iris) # Loading example data head(iris) # Sepal.Length Sepal.Width Petal.Length Petal.Width Species # 1 5.1 3.5 1.4 0.2 setosa # 2 4.9 3.0 1.4 0.2 setosa # 3 4.7 3.2 1.3 0.2 setosa # 4 4.6 3.1 1.5 0.2 setosa # 5 5.0 3.6 1.4 0.2 setosa # 6 5.4 3.9 1.7 0.4 setosa
Example: Extracting the eCDF Values from the ecdf() Function
iris_ecdf_fun <- ecdf(iris$Sepal.Length) # Calculate & extract eCDF values iris_ecdf_val <- iris_ecdf_fun(iris$Sepal.Length) iris_ecdf_val # [1] 0.273333333 0.146666667 0.073333333 0.060000000 0.213333333 0.346666667 # [7] 0.060000000 0.213333333 0.026666667 0.146666667 0.346666667 0.106666667 # [13] 0.106666667 0.006666667 0.533333333 0.486666667 0.346666667 0.273333333 # [19] 0.486666667 0.273333333 0.346666667 0.273333333 0.060000000 0.273333333 # [25] 0.106666667 0.213333333 0.213333333 0.300000000 0.300000000 0.073333333 # [31] 0.106666667 0.346666667 0.300000000 0.393333333 0.146666667 0.213333333 # [37] 0.393333333 0.146666667 0.026666667 0.273333333 0.213333333 0.033333333 # [43] 0.026666667 0.213333333 0.273333333 0.106666667 0.273333333 0.060000000 # [49] 0.306666667 0.213333333 0.920000000 0.766666667 0.913333333 0.393333333 # [55] 0.800000000 0.486666667 0.720000000 0.146666667 0.813333333 0.300000000 # [61] 0.213333333 0.553333333 0.593333333 0.633333333 0.433333333 0.866666667 # [67] 0.433333333 0.533333333 0.660000000 0.433333333 0.553333333 0.633333333 # [73] 0.720000000 0.633333333 0.766666667 0.813333333 0.886666667 0.866666667 # [79] 0.593333333 0.486666667 0.393333333 0.393333333 0.533333333 0.593333333 # [85] 0.346666667 0.593333333 0.866666667 0.720000000 0.433333333 0.393333333 # [91] 0.393333333 0.633333333 0.533333333 0.213333333 0.433333333 0.486666667 # [97] 0.486666667 0.660000000 0.273333333 0.486666667 0.720000000 0.533333333 # [103] 0.926666667 0.720000000 0.800000000 0.966666667 0.146666667 0.953333333 # [109] 0.866666667 0.946666667 0.800000000 0.766666667 0.886666667 0.486666667 # [115] 0.533333333 0.766666667 0.800000000 0.993333333 0.993333333 0.593333333 # [121] 0.913333333 0.433333333 0.993333333 0.720000000 0.866666667 0.946666667 # [127] 0.660000000 0.633333333 0.766666667 0.946666667 0.960000000 1.000000000 # [133] 0.766666667 0.720000000 0.633333333 0.993333333 0.720000000 0.766666667 # [139] 0.593333333 0.913333333 0.866666667 0.913333333 0.533333333 0.886666667 # [145] 0.866666667 0.866666667 0.720000000 0.800000000 0.660000000 0.553333333 |
iris_ecdf_fun <- ecdf(iris$Sepal.Length) # Calculate & extract eCDF values iris_ecdf_val <- iris_ecdf_fun(iris$Sepal.Length) iris_ecdf_val # [1] 0.273333333 0.146666667 0.073333333 0.060000000 0.213333333 0.346666667 # [7] 0.060000000 0.213333333 0.026666667 0.146666667 0.346666667 0.106666667 # [13] 0.106666667 0.006666667 0.533333333 0.486666667 0.346666667 0.273333333 # [19] 0.486666667 0.273333333 0.346666667 0.273333333 0.060000000 0.273333333 # [25] 0.106666667 0.213333333 0.213333333 0.300000000 0.300000000 0.073333333 # [31] 0.106666667 0.346666667 0.300000000 0.393333333 0.146666667 0.213333333 # [37] 0.393333333 0.146666667 0.026666667 0.273333333 0.213333333 0.033333333 # [43] 0.026666667 0.213333333 0.273333333 0.106666667 0.273333333 0.060000000 # [49] 0.306666667 0.213333333 0.920000000 0.766666667 0.913333333 0.393333333 # [55] 0.800000000 0.486666667 0.720000000 0.146666667 0.813333333 0.300000000 # [61] 0.213333333 0.553333333 0.593333333 0.633333333 0.433333333 0.866666667 # [67] 0.433333333 0.533333333 0.660000000 0.433333333 0.553333333 0.633333333 # [73] 0.720000000 0.633333333 0.766666667 0.813333333 0.886666667 0.866666667 # [79] 0.593333333 0.486666667 0.393333333 0.393333333 0.533333333 0.593333333 # [85] 0.346666667 0.593333333 0.866666667 0.720000000 0.433333333 0.393333333 # [91] 0.393333333 0.633333333 0.533333333 0.213333333 0.433333333 0.486666667 # [97] 0.486666667 0.660000000 0.273333333 0.486666667 0.720000000 0.533333333 # [103] 0.926666667 0.720000000 0.800000000 0.966666667 0.146666667 0.953333333 # [109] 0.866666667 0.946666667 0.800000000 0.766666667 0.886666667 0.486666667 # [115] 0.533333333 0.766666667 0.800000000 0.993333333 0.993333333 0.593333333 # [121] 0.913333333 0.433333333 0.993333333 0.720000000 0.866666667 0.946666667 # [127] 0.660000000 0.633333333 0.766666667 0.946666667 0.960000000 1.000000000 # [133] 0.766666667 0.720000000 0.633333333 0.993333333 0.720000000 0.766666667 # [139] 0.593333333 0.913333333 0.866666667 0.913333333 0.533333333 0.886666667 # [145] 0.866666667 0.866666667 0.720000000 0.800000000 0.660000000 0.553333333
Related Tutorials & Further Resources
Have a look at the following R tutorials. They discuss topics such as character strings, groups, numeric values, and extracting data.