[R] Quantiles in boxplot‏

peter dalgaard pdalgd at gmail.com
Sat Jan 14 17:40:09 CET 2012


On Jan 14, 2012, at 16:07 , René Brinkhuis wrote:

> 
> Based
> on your information I created a custom function for calculating the 
> first and third quartile according to the 'boxplot logic'.

A more compact (though not as readable) version is afforded by stats:::fivenum.

A convenient description is (I believe) that the hinges are the medians of the bottom and top halves of the sorted observations, with the middle observation counting in both groups if n is odd).

> x <- rnorm(121)
> fivenum(x)
[1] -2.4596038 -0.6034689  0.1105829  0.6686026  2.2580863
> median(sort(x)[1:floor((length(x)+1)/2)])
[1] -0.6034689
> median(sort(x)[ceiling((length(x)+1)/2):length(x)])
[1] 0.6686026

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list