From 25ce34baf0cc2f54db36d1f89de8adc1a9c72086 Mon Sep 17 00:00:00 2001 From: Fabian Greimel Date: Wed, 18 Sep 2019 10:30:50 +0200 Subject: [PATCH] Allow for weights in cut(x,[ w,] ngroups) --- src/extras.jl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/extras.jl b/src/extras.jl index 5e00bf70..7d14a5b7 100644 --- a/src/extras.jl +++ b/src/extras.jl @@ -1,4 +1,4 @@ -using Compat.Statistics +import StatsBase function fill_refs!(refs::AbstractArray, X::AbstractArray, breaks::AbstractVector, extend::Bool, allow_missing::Bool) @@ -133,7 +133,7 @@ function cut(x::AbstractArray{T, N}, breaks::AbstractVector; end """ - cut(x::AbstractArray, ngroups::Integer; + cut(x::AbstractArray, [w::AbstractWeights, ]ngroups::Integer; labels::Union{AbstractVector{<:AbstractString},Function}) Cut a numeric array into `ngroups` quantiles, determined using @@ -141,4 +141,9 @@ Cut a numeric array into `ngroups` quantiles, determined using """ cut(x::AbstractArray, ngroups::Integer; labels::Union{AbstractVector{<:AbstractString},Function}=default_formatter) = - cut(x, Statistics.quantile(x, (1:ngroups-1)/ngroups); extend=true, labels=labels) \ No newline at end of file + cut(x, StatsBase.quantile(x, (1:ngroups-1)/ngroups); extend=true, labels=labels) + +cut(x::AbstractArray, w::AbstractWeights, ngroups::Integer; + labels::Union{AbstractVector{<:AbstractString},Function}=default_formatter) = + cut(x, StatsBase.quantile(x, w, (1:ngroups-1)/ngroups); extend=true, labels=labels) +