Skip to content

Commit 25ce34b

Browse files
committed
Allow for weights in cut(x,[ w,] ngroups)
1 parent 7d06c34 commit 25ce34b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/extras.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Compat.Statistics
1+
import StatsBase
22

33
function fill_refs!(refs::AbstractArray, X::AbstractArray,
44
breaks::AbstractVector, extend::Bool, allow_missing::Bool)
@@ -133,12 +133,17 @@ function cut(x::AbstractArray{T, N}, breaks::AbstractVector;
133133
end
134134

135135
"""
136-
cut(x::AbstractArray, ngroups::Integer;
136+
cut(x::AbstractArray, [w::AbstractWeights, ]ngroups::Integer;
137137
labels::Union{AbstractVector{<:AbstractString},Function})
138138
139139
Cut a numeric array into `ngroups` quantiles, determined using
140140
[`quantile`](@ref).
141141
"""
142142
cut(x::AbstractArray, ngroups::Integer;
143143
labels::Union{AbstractVector{<:AbstractString},Function}=default_formatter) =
144-
cut(x, Statistics.quantile(x, (1:ngroups-1)/ngroups); extend=true, labels=labels)
144+
cut(x, StatsBase.quantile(x, (1:ngroups-1)/ngroups); extend=true, labels=labels)
145+
146+
cut(x::AbstractArray, w::AbstractWeights, ngroups::Integer;
147+
labels::Union{AbstractVector{<:AbstractString},Function}=default_formatter) =
148+
cut(x, StatsBase.quantile(x, w, (1:ngroups-1)/ngroups); extend=true, labels=labels)
149+

0 commit comments

Comments
 (0)