Hi everyone,
Can I suggest the following cosmetic change to cut.default (R-1.3.1), to
adjust the labels in the case that include.lowest = TRUE:
arrow:dma0jcr% diff -u cut.R my.cut.R
--- cut.R Tue Nov 13 12:28:35 2001
+++ my.cut.R Tue Nov 13 12:35:16 2001
@@ -25,6 +25,11 @@
ch.br[-nb], ",", ch.br[-1],
if(right)"]" else ")",
sep='')
else paste("Range", 1:(nb - 1),sep="_")
+ if (ok && include.lowest)
+ if (right)
+ labels[1] <- gsub("^\\(", "\\[",
labels[1])
+ else
+ labels[nb-1] <- gsub("\\)$",
"\\]",
labels[nb-1])
} else if (is.logical(labels) && !labels)
codes.only <- TRUE
else if (length(labels) != nb-1)
Thus we have (noticing the labels)
> pp <- rpois(10, lambda = 1)
> breaks <- c(0:2, Inf)
> cut(pp, breaks = breaks)
[1] NA (0,1] (0,1] (0,1] NA NA NA (0,1] (1,2] (1,2]
Levels: (0,1] (1,2] (2,Inf] > cut(pp, breaks = breaks, include.lowest = TRUE)
[1] [0,1] [0,1] [0,1] [0,1] [0,1] [0,1] [0,1] [0,1] (1,2] (1,2]
Levels: [0,1] (1,2] (2,Inf] > cut(pp, breaks = breaks, include.lowest = TRUE, right = FALSE)
[1] [0,1) [1,2) [1,2) [1,2) [0,1) [0,1) [0,1) [1,2)
[2,Inf]
[10] [2,Inf]
Levels: [0,1) [1,2) [2,Inf] > cut(pp, breaks = breaks, right = FALSE)
[1] [0,1) [1,2) [1,2) [1,2) [0,1) [0,1) [0,1) [1,2)
[2,Inf)
[10] [2,Inf)
Levels: [0,1) [1,2) [2,Inf)
Cheers, Jonathan.
--
Jonathan Rougier Science Laboratories
Department of Mathematical Sciences South Road
University of Durham Durham DH1 3LE
tel: +44 (0)191 374 2361, fax: +44 (0)191 374 7388
http://www.maths.dur.ac.uk/stats/people/jcr/jcr.html
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To:
r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>>>>> "JonR" == Jonathan Rougier <J.C.Rougier@durham.ac.uk> writes:JonR> Hi everyone, Can I suggest the following cosmetic change to JonR> cut.default (R-1.3.1), to adjust the labels in the case that JonR> include.lowest = TRUE: ..... JonR> Thus we have (noticing the labels) >> pp <- rpois(10, lambda = 1) breaks <- c(0:2, Inf) >> cut(pp, breaks =breaks) JonR> [1] NA (0,1] (0,1] (0,1] NA NA NA (0,1] (1,2] (1,2] JonR> Levels: (0,1] (1,2] (2,Inf] >> cut(pp, breaks = breaks, include.lowest = TRUE) JonR> [1] [0,1] [0,1] [0,1] [0,1] [0,1] [0,1] [0,1] [0,1] (1,2] (1,2] JonR> Levels: [0,1] (1,2] (2,Inf] >> cut(pp, breaks = breaks, include.lowest = TRUE, right = FALSE) JonR> [1] [0,1) [1,2) [1,2) [1,2) [0,1) [0,1) [0,1) [1,2) [2,Inf] .. JonR> Levels: [0,1) [1,2) [2,Inf] >> cut(pp, breaks = breaks, right = FALSE) JonR> [1] [0,1) [1,2) [1,2) [1,2) [0,1) [0,1) [0,1) [1,2) [2,Inf) .. JonR> Levels: [0,1) [1,2) [2,Inf) which sounds very reasonable. There is the slight chance to break old code however for people who made explicit use of the factor levels in things like indhigh <- fp == "[2, Inf)" I still believe we should do the change for 1.4. If there won't be further voices, I'll do. Martin Maechler <maechler@stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO D10 Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 <>< -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._