coarsen | R Documentation |
coarsen
can be used to obtain a factor from a vector, similar
to cut
, but with less technical and more "aesthetic"
labels of the factor levels.
coarsen(x,...)
## S3 method for class 'numeric'
coarsen(x,
n=5,
pretty=TRUE,
quantiles=!pretty,
breaks=NULL,
brackets=FALSE,
sep=if(brackets)";"else if(quantiles) "-" else " - ",
left="[",
right="]",
range=FALSE,
labels=NULL,
...)
x |
a vector, usually a numeric vector |
n |
number of categories of the resulting factor |
pretty |
a logical value, whether |
quantiles |
a logical value, whether |
breaks |
a vector of break points or |
brackets |
a logical value, whether the labels should include brackets. |
sep |
a character string, used as a separator between upper and lower boundaries in the labels. |
left |
a character string, to be used as the left bracket |
right |
a character string, to be used as the right bracket |
range |
a logical value, whether the minimum and maximum of
|
labels |
an optional character vector of labels. |
... |
further arguments, passed on to |
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]))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.