Whenever I compute quartiles with the quantile function in R for a vector whose size is equal to certain odd numbers (every number with the tens and units slot being greater than or equal to 15), I always get the third quarter with the smallest number of elements.
Examples
> t <- runif(n=15,min=1,max=19999)
> t.s <- cut(t, breaks=quantile(t,probs=seq(0,1,by=0.25)), include.lowest=T)
> summary(t.s)
[983,5.27e+03] (5.27e+03,9.63e+03] (9.63e+03,1.46e+04] (1.46e+04,1.88e+04]
4 4 3 4
> t <- sample.int(1000,111)
> t.s <- cut(t, breaks=quantile(t,probs=seq(0,1,by=0.25)), include.lowest=T)
> summary(t.s)
[7,264] (264,575] (575,787] (787,999]
28 28 27 28
Is this a feature of R or something to do with number theory?
There are 9 quantile algorithms to choose from. By default R uses type 7. Described in
?quantile. As noted if you choose other algorithms you will get other default behaviour.The Algorithms used are also outlined in the
?quantile