1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
\name{coarsen}
\alias{coarsen}
\alias{coarsen.numeric}
\title{Coarsen a vector into a factor with a lower number of levels}
\description{
\code{coarsen} can be used to obtain a factor from a vector, similar
to \code{\link[base]{cut}}, but with less technical and more "aesthetic"
labels of the factor levels.
}
\usage{
coarsen(x,\dots)
\method{coarsen}{numeric}(x,
n=5,
pretty=TRUE,
quantiles=!pretty,
breaks=NULL,
brackets=FALSE,
sep=if(brackets)";"else if(quantiles) "-" else " - ",
left="[",
right="]",
range=FALSE,
labels=NULL,
\dots)
}
\arguments{
\item{x}{a vector, usually a numeric vector}
\item{n}{number of categories of the resulting factor}
\item{pretty}{a logical value, whether \code{\link[base]{pretty}}
should be used to compute the breaks.}
\item{quantiles}{a logical value, whether \code{\link[stats]{quantile}}
should be used to compute the breaks.}
\item{breaks}{a vector of break points or \code{NULL}.}
\item{brackets}{a logical value, whether the labels should include brackets.}
\item{sep}{a character string, used as a separator between upper and
lower boundaries in the labels.}
\item{left}{a character string, to be used as the left bracket}
\item{right}{a character string, to be used as the right bracket}
\item{range}{a logical value, whether the minimum and maximum of
\code{x} should be included into \code{breaks}.}
\item{labels}{an optional character vector of labels.}
\item{\dots}{further arguments, passed on to \code{\link[base]{pretty}}
or \code{\link[stats]{quantile}} if applicable.
}
}
\examples{
x <- rnorm(200)
table(coarsen(x))
table(coarsen(x,quantiles=TRUE))
table(coarsen(x,brackets=TRUE))
table(coarsen(x,breaks=c(-1,0,1)))
table(coarsen(x,breaks=c(-1,0,1),
range=TRUE,labels=letters[1:4]))
}
\keyword{manip}
|