View source: R/specific_calculations.R
percentile | R Documentation |
Break down a vector into useful percentiles. If the 25th percentile is 10.5, for example, then 25 \ named numeric vector, a Compact Line Display, or a percentile plot.
percentile(
num,
cuts = c(0, 0.025, 0.1, 0.2, 0.25, 0.33, 0.5, 0.66, 0.75, 0.8, 0.85, 0.9, 0.95, 0.99,
0.9975, 1),
na.rm = FALSE,
cld = FALSE,
plot = FALSE,
...
)
num |
(Numeric) A vector. |
cuts |
(Numeric) A vector of percentiles to calculate. |
na.rm |
(Logical) If |
cld |
( |
plot |
(Logical) If |
... |
Extra parameters that are passed to plot() if |
By default, returns a named numeric vector of percentiles and their
values.
If cld
has a Character
string in it, then returns a
glue/Character vector.
If plot = TRUE
, returns a scatter plot of the percentiles along X
and their values along Y.
Desi Quintans (http://www.desiquintans.com)
# round(runif(20, min = 0, max = 29))
vec <- c(28, 23, 3, 28, 6, 5, 21, 19, 9, 17, 22, 23, 26, 9, 5, 20, 19, 24, 3, 27)
perc <- percentile(vec)
perc
#> 0% 10% 20% 25% 33% 50% 66% 75% 80% 85% 90% 95% 99% 100%
#> 3.00 4.80 5.80 8.25 11.16 19.50 22.54 23.25 24.40 26.15 27.10 28.00 28.00 28.00
perc["66%"]
#> 66%
#> 22.54
# You can also just ask for one percentile:
percentile(vec, 0.66)
#> 66%
#> 22.54
# You can get a _C_ompact _L_ine _D_isplay of your results. Access each element
# of your results as `{p1}`, `{p2}`, `{p3}`, etc.
percentile(vec, c(0.05, 0.5, 0.95), cld = "{p1} ({p2}) {p3}")
#> 3 (19.5) 28
## Not run:
percentile(vec, plot = TRUE)
## End(Not run)
# Produces a scatter plot with percentile cuts on the X axis, value on the Y axis, and
# the points joined by a line to show the shape of the data.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.