Skip to content

Commit

Permalink
Allow for weights in cut(x,[ w,] ngroups)
Browse files Browse the repository at this point in the history
  • Loading branch information
greimel committed Sep 18, 2019
1 parent 7d06c34 commit 25ce34b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/extras.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Compat.Statistics
import StatsBase

function fill_refs!(refs::AbstractArray, X::AbstractArray,
breaks::AbstractVector, extend::Bool, allow_missing::Bool)
Expand Down Expand Up @@ -133,12 +133,17 @@ 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
[`quantile`](@ref).
"""
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)
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)

0 comments on commit 25ce34b

Please sign in to comment.