Check out the quantile()
function. https://stat.ethz.ch/R-manual/R-devel/library/stats/html/quantile.html
There is an underlying distribution quantile calculation type
based on the SAS
method.
Type 3 - SAS definition: nearest even order statistic. γ = 0 if g = 0 and j is even, and 1 otherwise.
Use the function like this:
quantile(iris$Sepal.Length, probs = c(.02, .05, .98, .99, .95), type=3)
2% 5% 98% 99% 95%
4.4 4.6 7.7 7.7 7.2
You can use various methods, such as sapply()
to execute quantile()
on multiple variables. ex.
t(sapply(iris[1:4], quantile, probs = c(.02, .05, .98, .99, .95), type=3))
2% 5% 98% 99% 95%
Sepal.Length 4.4 4.6 7.7 7.7 7.2
Sepal.Width 2.2 2.3 4.0 4.1 3.8
Petal.Length 1.2 1.3 6.6 6.7 6.1
Petal.Width 0.1 0.2 2.4 2.5 2.3