R Percentiles
Percentiles
Percentiles are used in statistics to give you a number that describes the value that a given percent of the values are lower than.
If we take a look at the values of the wt
(weight) variable from the mtcars
data set:
Observation of wt (weight)
1.513 | 1.615 | 1.835 | 1.935 | 2.140 | 2.200 | 2.320 | 2.465 |
2.620 | 2.770 | 2.780 | 2.875 | 3.150 | 3.170 | 3.190 | 3.215 |
3.435 | 3.440 | 3.440 | 3.440 | 3.460 | 3.520 | 3.570 | 3.570 |
3.730 | 3.780 | 3.840 | 3.845 | 4.070 | 5.250 | 5.345 | 5.424 |
What is the 75. percentile of the weight of the cars? The answer is 3.61 or 3 610 lbs, meaning that 75% or the cars weight 3 610 lbs or less:
Example
Data_Cars <- mtcars
# c() specifies which percentile you want
quantile(Data_Cars$wt, c(0.75))
Result:
75% 3.61
If you run the quantile()
function without specifying the c()
parameter, you will get
the percentiles of 0, 25, 50, 75 and 100:
Example
Data_Cars <- mtcars
quantile(Data_Cars$wt)
Result:
0% 25% 50% 75% 100% 1.51300 2.58125 3.32500 3.61000 5.42400
Quartiles
Quartiles are data divided into four parts, when sorted in an ascending order:
- The value of the first quartile cuts off the first 25% of the data
- The value of the second quartile cuts off the first 50% of the data
- The value of the third quartile cuts off the first 75% of the data
- The value of the fourth quartile cuts off the 100% of the data
Use the quantile()
function to get the quartiles.
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.