duration

Methods

Method Reference: duration.discretize

duration: bin = discretize (D, edges)
duration: bin = discretize (D, N)
duration: bin = discretize (D, dur)
duration: bin = discretize (D, unit)
duration: Y = discretize (…, values)
duration: C = discretize (…, ’categorical’)
duration: C = discretize (…, ’categorical’, names)
duration: Y = discretize (…, ’IncludedEdge’, side)
duration: [bin, edges] = discretize (…)

Group durations into bins.

bin = discretize (D, edges) returns the index of the bin each element of D falls into, given a duration vector of bin edges. Bin j covers [edges(j), edges(j+1)), except the last, which is closed at both ends. Elements outside the edges, and NaN durations, return NaN.

bin = discretize (D, N) uses N bins of uniform width, placed on whole time units where that is possible.

bin = discretize (D, dur) uses bins of the fixed width dur, a scalar duration, and bin = discretize (D, unit) uses bins one unit wide, where unit is one of 'second', 'minute', 'hour', 'day', 'week', 'month', 'quarter', 'year', 'decade' or 'century'. A month is a twelfth of the 365.2425-day year that years counts, since a duration has no calendar.

The remaining options are as for the top-level discretize.

Deviation from MATLAB, for an explicitly requested bin count only. Every other way of binning – automatic, by width, by unit, or by explicit edges – agrees with MATLAB exactly. Asked for a bin count, MATLAB chooses between whole-unit and decimal widths in a way that is not monotonic in the data: over seconds ([0 16.8]) it gives 7 bins of 2.5 s, over the wider seconds ([0 17.15]) 7 bins of 3 s, and decimal widths again above that. It also discards bins, giving hours (0:24) in 7 bins a 4-hour width that covers the data in 6. A whole time unit is used here whenever it still needs every bin requested, which is monotonic and never wastes a bin.

See also: histcounts, discretize

Source Code: duration