Skip to content

Commit 930f0be

Browse files
committed
Allow for weights in cut(x,[ w,] ngroups)
1 parent 0ede6dc commit 930f0be

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
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: 6 additions & 2 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)
@@ -166,7 +166,7 @@ function cut(x::AbstractArray{T, N}, breaks::AbstractVector;
166166
end
167167

168168
"""
169-
cut(x::AbstractArray, ngroups::Integer;
169+
cut(x::AbstractArray, [w::AbstractWeights, ]ngroups::Integer;
170170
labels::Union{AbstractVector{<:AbstractString},Function})
171171
172172
Cut a numeric array into `ngroups` quantiles, determined using
@@ -175,3 +175,7 @@ Cut a numeric array into `ngroups` quantiles, determined using
175175
cut(x::AbstractArray, ngroups::Integer;
176176
labels::Union{AbstractVector{<:AbstractString},Function}=default_formatter) =
177177
cut(x, Statistics.quantile(x, (1:ngroups-1)/ngroups); extend=true, labels=labels)
178+
179+
cut(x::AbstractArray, w::AbstractWeights, ngroups::Integer;
180+
labels::Union{AbstractVector{<:AbstractString},Function}=default_formatter) =
181+
cut(x, StatsBase.quantile(x, w, (1:ngroups-1)/ngroups); extend=true, labels=labels)

0 commit comments

Comments
 (0)