Skip to content

Commit

Permalink
quantile: accept integer arrays (closes #1333)
Browse files Browse the repository at this point in the history
nolta committed Oct 5, 2012
1 parent f9051bc commit 0a3b7a3
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions base/statistics.jl
Original file line number Diff line number Diff line change
@@ -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]]
3 changes: 2 additions & 1 deletion test/statistics.jl
Original file line number Diff line number Diff line change
@@ -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.