How to calculate quartiles and other percentiles? Given the following data:
972, 975, 985, 993, 993, 995, 998, 1001, 1004, 1007, 1008, 1009, 1011, 1015, 1016, 1020, 1022, 1032
I calculate the lower quartile as follows:
Number of values: 18, Number of 'gaps': 17.
Lower quartile is at 17/4 + 1 = 5.25th value.
5.25th value is 993 + (995 - 993) x 0.25 = 993.5
Upper quartile is at 3 x 17/4 + 1 = 13.75th value.
13.75th value is 1011 + (1015 - 1011) x 0.75 = 1014
Both the Excel QUARTILE function and the R quantile function agree with me. However the book I am using (Understanding Statistics by Graham Upton and Ian Cook) give different answers (993 and 1015 respectively). I'm confused. Which is correct?
 A: As noted by Hyndman and Fan (1996) there are multiple definition of quantiles and different implementations, so it is very likely that you found different estimates calculated from the same data (each of them equally "correct"). I'm afraid that to mention all the differences I'd need to literally reproduce the paper in here, so maybe you should rather read it yourself, as it is available online:

Hyndman, R.J., & Fan, Y. (1996). Sample Quantiles in Statistical
  Packages. American Statistician, 50(4): 361-365.

Notice that quantile function for R (in fact implemented by Hyndman) enables you to calculate all the nine types of quantiles (using type parameter), check ?quantile to read more. So even R gave you only one of the possible estimates.
As about the estimates, types 1, 2, 3, 5, 6, 8, and 9 return the values reproduced in your book, type 7 (default in quantile function for R) is what you obtained and type 4 disagrees with both estimates.

A: There might be several ways to compute quartiles.
One of the methods is your way, I am pretty sure that R and Excel using the way that you've used. This is the defaul type = 7 in R
However, another way of computing quartile is using the formula: Ly = (n+1)y/100
Ly is the location of the yth percentile (As all the quantile can be transformed into percentile), n is the number of observations.
Using the second method the first quartile will be 25th percentile and Ly = (18+1)25/100 = 4.75 which took 4th value 993 and plus 0.75(5th - 4th) = 0.75(993-993) = 0 --> first quartile is 993.
This method is used by CFA Institute and in R is type = 6.
I was confused at first but now I think I need to be flexible lol :D
