Skip to content
Browse files

Document and export cut_interval and cut_number

  • Loading branch information...
1 parent 682adcb commit 036110c7c4ae55c691384587931415ae8a6a02ed @hadley committed
Showing with 57 additions and 26 deletions.
  1. +2 −0 NAMESPACE
  2. +21 −26 R/utilities-break.r
  3. +18 −0 man/cut_interval.Rd
  4. +16 −0 man/cut_number.Rd
View
2 NAMESPACE
@@ -183,6 +183,8 @@ export(theme_text)
export(theme_update)
export(opts)
S3method(print, theme)
+export(cut_interval)
+export(cut_number)
S3method(rweave, list)
S3method(rweave, matrix)
S3method(cweave, list)
View
47 R/utilities-break.r
@@ -1,37 +1,32 @@
-# Discretise continuous variable, equal interval length.
-# Cut numeric vector into intervals of equal length.
-#
-# @param numeric vector
-# @param number of intervals to create, OR
-# @param length of each interval
-# @param other arguments passed on to \code{\link{cut}}
-# @keyword manip
-# @seealso \code{\link{cut_number}}
-#
-#X table(cut_interval(1:100, n = 10))
-#X table(cut_interval(1:100, n = 11))
-#X table(cut_interval(1:100, length = 10))
+#' Cut numeric vector into intervals of equal length.
+#'
+#' @param x numeric vector
+#' @param n number of intervals to create, OR
+#' @param length length of each interval
+#' @param ... other arguments passed on to \code{\link{cut}}
+#' @seealso \code{\link{cut_number}}
+#' @export
+#' @examples
+#' table(cut_interval(1:100, n = 10))
+#' table(cut_interval(1:100, n = 11))
+#' table(cut_interval(1:100, length = 10))
cut_interval <- function(x, n = NULL, length = NULL, ...) {
cut(x, breaks(x, "width", n, length), include.lowest = TRUE, ...)
}
-# Discretise continuous variable, equal number of points.
-# Cut numeric vector into intervals containing equal number of points.
-#
-# @param numeric vector
-# @param number of intervals to create, OR
-# @param length of each interval
-# @param other arguments passed on to \code{\link{cut}}
-# @keyword manip
-# @seealso \code{\link{cut_interval}}
-#X table(cut_number(runif(1000), n = 10))
+#' Cut numeric vector into intervals containing equal number of points.
+#'
+#' @param x numeric vector
+#' @param n number of intervals to create
+#' @param ... other arguments passed on to \code{\link{cut}}
+#' @seealso \code{\link{cut_interval}}
+#' @export
+#' @examples
+#' table(cut_number(runif(1000), n = 10))
cut_number <- function(x, n = NULL, ...) {
cut(x, breaks(x, "n", n), include.lowest = TRUE, ...)
}
-# Discretise continuous vector
-# Method that powers \code{\link{cut_number}} and \code{\link{cut_interval}}
-# @keyword internal
breaks <- function(x, equal, nbins = NULL, binwidth = NULL) {
equal <- match.arg(equal, c("numbers", "width"))
if ((!is.null(nbins) && !is.null(binwidth)) || (is.null(nbins) && is.null(binwidth))) {
View
18 man/cut_interval.Rd
@@ -0,0 +1,18 @@
+\name{cut_interval}
+\alias{cut_interval}
+\title{Cut numeric vector into intervals of equal length.}
+\usage{cut_interval(x, n, length, ...)}
+
+\description{
+ Cut numeric vector into intervals of equal length.
+}
+\seealso{\code{\link{cut_number}}}
+\arguments{
+ \item{x}{numeric vector}
+ \item{n}{number of intervals to create, OR}
+ \item{length}{length of each interval}
+ \item{...}{other arguments passed on to \code{\link{cut}}}
+}
+\examples{table(cut_interval(1:100, n = 10))
+table(cut_interval(1:100, n = 11))
+table(cut_interval(1:100, length = 10))}
View
16 man/cut_number.Rd
@@ -0,0 +1,16 @@
+\name{cut_number}
+\alias{cut_number}
+\title{Cut numeric vector into intervals containing equal number of points.}
+\usage{cut_number(x, n, ...)}
+
+\description{
+ Cut numeric vector into intervals containing equal number
+ of points.
+}
+\seealso{\code{\link{cut_interval}}}
+\arguments{
+ \item{x}{numeric vector}
+ \item{n}{number of intervals to create}
+ \item{...}{other arguments passed on to \code{\link{cut}}}
+}
+\examples{table(cut_number(runif(1000), n = 10))}

0 comments on commit 036110c

Please sign in to comment.
Something went wrong with that request. Please try again.