Skip to content
Browse files

quantile: accept integer arrays (closes #1333)

  • Loading branch information...
1 parent f9051bc commit 0a3b7a313e7e2e8c3dac8c30b194a48c467b0459 @nolta nolta committed Oct 5, 2012
Showing with 5 additions and 4 deletions.
  1. +3 −3 base/statistics.jl
  2. +2 −1 test/statistics.jl
View
6 base/statistics.jl
@@ -351,11 +351,11 @@ function quantile(x, qs)
if lx > 0 && lqs > 0
index = 1 + (lx-1) * bqs
- lo = int(floor(index))
- hi = int(ceil(index))
+ lo = ifloor(index)
+ hi = iceil(index)
sortedX = sort(x)
i = index .> lo
- ret = sortedX[lo]
+ ret = float(sortedX[lo])
i = [1:length(i)][i]
h = (index - lo)[i]
ret[i] = (1-h) .* ret[i] + h .* sortedX[hi[i]]
View
3 test/statistics.jl
@@ -12,5 +12,6 @@
@assert hist([1,2,3],10) == [1,0,0,0,0,1,0,0,0,1]
@assert histc([1,2,3],[0,2,4]) == [1,2,0]
+@assert quantile([1,2,3,4],0.5) == 2.5
@assert quartile([1., 3])[2] == median([1., 3])
-@assert decile(1. * [0:100])[1] == 10.0
+@assert decile([0.:100.])[1] == 10.0

0 comments on commit 0a3b7a3

Please sign in to comment.
Something went wrong with that request. Please try again.