@@ -65,17 +65,17 @@ also accept them.
6565 outside of the breaks; when `true`, breaks are automatically added to include all
6666 values in `x`, and the upper bound is included in the last interval.
6767* `labels::Union{AbstractVector,Function}: a vector of strings giving the names to use for
68- the intervals; or a function `f(from, to, i; extend )` that generates the labels from the
68+ the intervals; or a function `f(from, to, i; closed )` that generates the labels from the
6969 left and right interval boundaries and the group index. Defaults to
70- `string("[", from, ", " , to, extend ? "]" : ")")`, e.g. `"[1, 5)"` .
70+ `"[ from, to)"` (or `"[from , to]"` for the rightmost interval if `extend == true`) .
7171* `allow_missing::Bool=true`: when `true`, values outside of breaks result in missing values.
7272 only supported when `x` accepts missing values.
7373
7474# Examples
7575```jldoctest
7676julia> using CategoricalArrays
7777
78- julia> x = collect( -1:0.5:1) ;
78+ julia> x = -1:0.5:1;
7979
8080julia> cut(x, [0, 1], extend=true)
81815-element CategoricalArray{String,1,UInt32}:
@@ -85,6 +85,8 @@ julia> cut(x, [0, 1], extend=true)
8585 "[0.0, 1.0]"
8686 "[0.0, 1.0]"
8787
88+ julia> x = -1:0.5:1;
89+
8890julia> cut(x, 2)
89915-element CategoricalArray{String,1,UInt32}:
9092 "[-1.0, 0.0)"
@@ -93,6 +95,8 @@ julia> cut(x, 2)
9395 "[0.0, 1.0]"
9496 "[0.0, 1.0]"
9597
98+ julia> x = -1:0.5:1;
99+
96100julia> cut(x, 2, labels=["A", "B"])
971015-element CategoricalArray{String,1,UInt32}:
98102 "A"
@@ -111,22 +115,6 @@ julia> cut(x, 3, labels=fmt)
111115 "grp 2 (-0.333333//0.333333)"
112116 "grp 3 (0.333333//1.0)"
113117 "grp 3 (0.333333//1.0)"
114-
115- julia> using StatsBase: ecdf
116-
117- julia> percentile(x) = round(Int,100*parse(Float64,x))
118- percentile (generic function with 1 method)
119-
120- julia> fmt2(from, to, i; closed) = "P$(percentile(from))P$(percentile(to))"
121- fmt2 (generic function with 1 method)
122-
123- julia> cut(ecdf(x)(x), 3, labels=fmt2)
124- 5-element CategoricalArray{String,1,UInt32}:
125- "P20P47"
126- "P20P47"
127- "P47P73"
128- "P73P100"
129- "P73P100"
130118```
131119"""
132120function cut (x:: AbstractArray{T, N} , breaks:: AbstractVector ;
0 commit comments