Felix Andrews
2010-Apr-29 00:04 UTC
[Rd] bug in cut.POSIXt(..., breaks = <numeric>) and cut.Date
x <- seq(as.POSIXct("2000-01-01"), by = "days", length = 20) cut(x, breaks = 3) # Error in `levels<-.factor`(`*tmp*`, value = character(0)) : # number of levels differs cut(as.Date(x), breaks = 3) # Error in `levels<-.factor`(`*tmp*`, value = character(0)) : # number of levels differs Index: base/R/datetime.R ==================================================================--- base/R/datetime.R (revision 51857) +++ base/R/datetime.R (working copy) @@ -775,7 +775,11 @@ } } else stop("invalid specification of 'breaks'") res <- cut(unclass(x), unclass(breaks), labels = labels, right right, ...) - if(is.null(labels)) levels(res) <- as.character(breaks[-length(breaks)]) + if(is.null(labels)) { + if (is.numeric(breaks)) + levels(res) <- as.character(x[!duplicated(res)]) + else levels(res) <- as.character(breaks[-length(breaks)]) + } res } Index: base/R/dates.R ==================================================================--- base/R/dates.R (revision 51857) +++ base/R/dates.R (working copy) @@ -362,7 +362,11 @@ } else stop("invalid specification of 'breaks'") res <- cut(unclass(x), unclass(breaks), labels = labels, right = right, ...) - if(is.null(labels)) levels(res) <- as.character(breaks[-length(breaks)]) + if(is.null(labels)) { + if (is.numeric(breaks)) + levels(res) <- as.character(x[!duplicated(res)]) + else levels(res) <- as.character(breaks[-length(breaks)]) + } res } Regards -Felix -- Felix Andrews / ??? Postdoctoral Fellow Integrated Catchment Assessment and Management (iCAM) Centre Fenner School of Environment and Society [Bldg 48a] The Australian National University Canberra ACT 0200 Australia M: +61 410 400 963 T: + 61 2 6125 4670 E: felix.andrews at anu.edu.au CRICOS Provider No. 00120C -- http://www.neurofractal.org/felix/
Ben Bolker
2010-Apr-29 12:29 UTC
[Rd] bug in cut.POSIXt(..., breaks = < numeric> ) and cut.Date
Felix Andrews <felix <at> nfrac.org> writes:> > x <- seq(as.POSIXct("2000-01-01"), by = "days", length = 20) > > cut(x, breaks = 3) > # Error in `levels<-.factor`(`*tmp*`, value = character(0)) : > # number of levels differs > > cut(as.Date(x), breaks = 3) > # Error in `levels<-.factor`(`*tmp*`, value = character(0)) : > # number of levels differsIs this the same? http://article.gmane.org/gmane.comp.lang.r.devel/22155/match=cut+posixt