Bug 14961 - cut.Date give bogus answers with unsorted breaks
cut.Date give bogus answers with unsorted breaks
Status: CLOSED FIXED
Product: R
Classification: Unclassified
Component: Analyses
R 2.14.1
Other Linux
: P5 normal
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-06-26 16:00 UTC by Kevin Buhr
Modified: 2012-06-26 16:18 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Buhr 2012-06-26 16:00:45 UTC
In contrast to cut.default, which works correctly with unsorted "breaks" argument, the cut.Date method assumes "breaks" are already sorted and produces bogus answers if they aren't.

That is, this works correctly:

> cut.default(c(2,4,6), breaks=c(1,3,5,7))
[1] (1,3] (3,5] (5,7]
Levels: (1,3] (3,5] (5,7]
> cut.default(c(2,4,6), breaks=c(7,5,3,1))
[1] (1,3] (3,5] (5,7]
Levels: (1,3] (3,5] (5,7]
>

but this gives different answers depending on ordering of breaks:

> cut.Date(as.Date(c("2012-02-01","2012-04-01","2012-06-01")), breaks=as.Date(c("2012-01-01","2012-03-01","2012-05-01","2012-07-01")))
[1] 2012-01-01 2012-03-01 2012-05-01
Levels: 2012-01-01 2012-03-01 2012-05-01
> cut.Date(as.Date(c("2012-02-01","2012-04-01","2012-06-01")), breaks=as.Date(c("2012-07-01","2012-05-01","2012-03-01","2012-01-01")))
[1] 2012-07-01 2012-05-01 2012-03-01
Levels: 2012-07-01 2012-05-01 2012-03-01
>