Bug 16802 - Cut breaks are not unique if all(x == 0)
Summary: Cut breaks are not unique if all(x == 0)
Alias: None
Product: R
Classification: Unclassified
Component: Misc (show other bugs)
Version: R 3.2.4
Hardware: x86_64/x64/amd64 (64-bit) OS X Yosemite
: P5 normal
Assignee: R-core
Depends on:
Reported: 2016-04-07 14:00 UTC by joey reid
Modified: 2016-04-07 14:00 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description joey reid 2016-04-07 14:00:49 UTC
Cut uses the magnitude of the only unique value to set the sequence steps size for calculating breaks. This results in no unique breaks when that only unique value of x is 0.

*Steps to reproduce*
cut(rep(0L, 7), breaks = 3)

*Expected outcome*
Like this: cut(rep(1L, 7), breaks = 3), but centered on 0 instead of 1.

*Actual Results*
Error in cut.default(rep(0L, 7), breaks = 3) : 'breaks' are not unique

*Additional Info*
The problem is that when the range of the data is zero, cut defines a sequence using the minimum of the data as the base for the step size. 

dx <- abs(rx[1L])
breaks <- seq.int(rx[1L] - dx/1000, rx[2L] + dx/1000, length.out = nb)

Since dx = 0 when all(x == 0) the breaks will never be unique. It seems like there's no need to base the step size on the magnitude of the only value in x, just using 1/1000 would be sufficient.