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