32

I can use R summary function to get min, max and percentiles(25, 75).

How can i use summary to get arbitrary quantiles like 90th percentile and 99th percentile in summary stats?

Sathish
  • 20,660
  • 24
  • 63
  • 71
  • 1
    I don't think you can. Use the `quantile` function. – Arun Mar 27 '13 at 13:06
  • 1
    you could create your own `summary` function, starting with the code `getS3method( 'summary' , 'default' )` and changing the three lines starting at `qq <- stats::quantile(object)` to output the quantiles you want.. :) – Anthony Damico Mar 27 '13 at 14:19

1 Answers1

52

Use quantile function

quantile(x, c(.90, .99))

Example:

> set.seed(1)
> x <- rnorm(100)
> summary(x)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
-2.2150 -0.4942  0.1139  0.1089  0.6915  2.4020 
> quantile(x, c(.25, .50,  .75, .90, .99))
       25%        50%        75%        90%        99% 
-0.4942425  0.1139092  0.6915454  1.1810651  2.1749017 
Jilber Urbina
  • 58,147
  • 10
  • 114
  • 138
  • 12
    Take care when using `quantile()` - because the defaults may not give you what you're expecting. For example, `quantile(x, 0.99)` could be greater than `max(x)`. Read about the "type" parameter in the [documentation](https://stat.ethz.ch/R-manual/R-devel/library/stats/html/quantile.html). Note: This should be a comment but I don't have the rep. – Andre Jones Oct 21 '15 at 15:58