[Rd] labels returned by cut() when include.lowest=T (PR#1263)

maechler@stat.math.ethz.ch maechler@stat.math.ethz.ch
Tue, 15 Jan 2002 18:07:56 +0100 (MET)


>>>>> "StEgl" == Stephen Eglen <stephen@cogsci.ed.ac.uk> writes:

    StEgl> Full_Name: Stephen Eglen
    StEgl> Version: 1.4
    StEgl> OS: Redhat Linux 7.1
    StEgl> Submission from: (NULL) (128.252.204.36)


    StEgl> I think the brackets in the levels of cut() are
    StEgl> slightly incorrect when include.lowest is TRUE.

    StEgl> For example:

    >> table(cut( c(1,4), include.lowest=T, right=F, breaks=c(1,2,3,4)))

    StEgl> [1,2) [2,3) [3,4) 
    StEgl> 1     0     1 

    StEgl> I think the last range in this case should be [3,4].  A similar
    StEgl> problem exists for the first range when right=T.

    StEgl> Here is a possible patch against 1.4.0, which on the
    StEgl> above example gives:

    StEgl> [1,2) [2,3) [3,4] 
    StEgl> 1     0     1 

    StEgl> Stephen

  *** /tmp/cut.R.orig716Cri	Mon Jan 14 22:58:12 2002
  --- /tmp/cut.R716P1o	Mon Jan 14 22:58:12 2002
  ***************
  *** 25,30 ****
  --- 25,35 ----
			   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] <- sub("\\(", "\\[", labels[1])
  +           else
  +             labels[nb-1] <- sub(")", "]", labels[nb-1])
	} else if (is.logical(labels) && !labels)
	    codes.only <- TRUE
	else if (length(labels) != nb-1)

------

Thank you.
{I've fixed it using  ``substring() <- '' instead of sub()}.

Martin

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._