Skip to content

Instantly share code, notes, and snippets.

@wrathematics
Created September 29, 2014 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wrathematics/77e75c3340b51a394526 to your computer and use it in GitHub Desktop.
Save wrathematics/77e75c3340b51a394526 to your computer and use it in GitHub Desktop.
Quantile algorithms and numerical issues
set.seed(1234)
x <- rnorm(10)/1e7
quantile(x, type=1)
# 0% 25% 50% 75% 100%
# -2.345698e-07 -8.900378e-08 -5.644520e-08 4.291247e-08 1.084441e-07
quantile(x, type=4)
# 0% 25% 50% 75% 100%
# -2.345698e-07 -1.048552e-07 -5.644520e-08 3.532770e-08 1.084441e-07
all.equal(quantile(x, type=1), quantile(x, type=4))
# [1] "Mean relative difference: 0.1776594"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment