labelise | R Documentation |
Set the label
, as well as the units
attributes to an object.
The label can be used for better display as plot axes labels, or as table
headers in pretty-formatted R outputs. The units are usually associated to
the label in axes labels for plots. cl()
is a shortcut for concatenate
(c()
) and labelise()
.
labelise(x, label, units = NULL, as_labelled = FALSE, ...)
labelize(x, label, units = NULL, as_labelled = FALSE, ...)
## Default S3 method:
labelise(x, label, units = NULL, as_labelled = FALSE, ...)
## S3 method for class 'data.frame'
labelise(x, label, units = NULL, as_labelled = FALSE, self = TRUE, ...)
cl(..., label = NULL, units = NULL, as_labelled = FALSE)
unlabelise(x, ...)
unlabelize(x, ...)
## Default S3 method:
unlabelise(x, ...)
## S3 method for class 'data.frame'
unlabelise(x, self = TRUE, ...)
x |
An object. |
label |
The character string to set as |
units |
The units (optional) as a character string to set for |
as_labelled |
Should the object be converted as a |
... |
Further arguments: items to be concatenated in a vector using
|
self |
Do we label the |
The same mechanism as the one used in package Hmisc is used
here. However, Hmisc always add the labelled class to an object,
while here, this is optional. Setting this class make the object more nicely
printed, and subsettable without loosing these attributes. But it conflicts
with a class of the same name in package haven, used for other purposes.
So, here, one can also opt not to set it, using as_labelled = FALSE
.
The x
object plus a label
attribute, and possibly, a units
attribute.
Philippe Grosjean phgrosjean@sciviews.org
label()
, units()
# Labelise a vector:
x <- 1:10
x <- labelise(x, label = "A suite of integers", units = "cm")
x
# or, in a single operation:
x <- cl(1:10, label = "A suite of integers", units = "cm")
x
# Not adding the labelled class:
x <- cl(1:10, label = "Integers", units = "cm", as_labelled = FALSE)
x
# Unlabelising a labelised object
unlabelise(x)
# Labelise a data.frame
iris <- labelise(datasets::iris, "The famous iris dataset")
unlabelise(iris)
# but if you indicate self = FALSE, you can labelise variables within the
# data.frame (use a list or character vector of same length as x, or a
# named list or character vector):
iris <- labelise(iris, self = FALSE, label = list(
Sepal.Length = "Length of the sepals",
Petal.Length = "Length of the petals"
), units = c(rep("cm", 4), NA))
iris <- unlabelise(iris, self = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.