Take a dataset, sort the data from smallest to largest and split it in 4 equal subsets. The quartiles are the values of the dataset that cut it off in 4.
Quartiles are called:
- Q1: the first quartile under which the first 25% of the data in the set can be found,
- Q2: the second quartile under which the first 50% of the data in the set can be found (by the way, Q2 is also the median),
- Q3: the third quartile under which the first 75% of the data in the set can be found.
In addition, one refers to:
- Q0: the minimum value in the set,
- Q4: the maximum value in the set.
For info, note that the set of data between Q1 and Q3 (which contains the middle 50% of the data) is the interquartile range (IQR).
In R, quartiles may be obtained using the function
quantile() (NB: this is not a typo, it is quaNtile and not quaRtile, there is a good explanation for it, believe me…). If you choose to use only
quantile() with no other argument than the vector containing the dataset, R returns Q0, Q1, Q2, Q3, Q4 and Q5. If you need only Q1, Q2 and Q3, say it in an extra argument (see the following example):
my.dataset <- c(1,2,3,4,5,6,7,8,9,10) quantile(my.dataset) quantile(my.dataset, c(0.25, 0.5, 0.75))