Skip to content

Commit 982c430

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

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
1010
Missings = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28"
1111
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
1212
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
13+
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
1314
Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
1415

1516
[compat]

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)