# [R] Calculating Percentile in R

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Jun 18 09:12:21 CEST 2007

```On Sun, 17 Jun 2007, Megh Dal wrote:

> Hi all,
>
> I have a problem on how R calculates Percentiles :
>
> Suppose I have following data set:
>> data1
>  [1] -16648185 -14463457 -14449400 -13905309 -13443436 -13234755 -12956282 -11660896
>  [9] -10061040  -9805005  -9789583  -9754642  -9562164  -9391709  -9212182  -9151073
> [17]  -9092732  -9068214  -8978151  -8943912  -8761890  -8632106  -8541580  -8501249
> [25]  -8234466  -8219015  -8193543  -7488279  -7340768  -7236684  -7225458  -7159465
> [33]  -6819625  -6810858  -6755620  -6626439  -6610901  -6551762  -6207377  -6192583
> [41]  -6106783  -6077051  -6035300  -6035195  -6019017  -5954375  -5946285  -5886082
> [49]  -5880402  -5723368  -5668698  -5599168  -5548276  -5445734  -5412312  -5384707
> [57]  -5309365  -5303425  -5285274  -5204585  -5096301  -5092182  -5053349  -5041533
> [65]  -5021234  -5005402  -4984232  -4981990  -4964457  -4936653  -4920384  -4918021
> [73]  -4895351  -4843258  -4824730  -4774792  -4771018  -4616156  -4590430  -4444262
> [81]  -4443954  -4435397  -4415112  -4374465  -4341858  -4267891  -4252410  -4185021
> [89]  -4164458  -4158863  -4020436  -4006030  -3975819  -3959667  -3916414  -3876878
> [97]  -3765340  -3729338  -3713670  -3634991
>
> Now the 5th percentile should be value corresponding to 0.05*(100+1) =
> 5.05 = 5 (rounded)

According to you, but not according to ?quantile, which gives you a choice
of 9 definitions, yours not being the default.

> hence : -13443436
>
> But R give the value :
>> quantile(data1, 0.05)
>       5%
> -13245189
>
> Can anyone clarify me on this regards?
>
> Thanks
> Megh
>
>
> 	[[alternative HTML version deleted]]
>
> http://www.R-project.org/posting-guide.html