View source: R/assign_labels.R
assign_labels | R Documentation |
Assign variable and values labels to a variable or variables in a data frame.
Labels are stored as attributes ("label"
for variable labels and "labels"
)
for value labels.
assign_labels(x, ...)
## S3 method for class 'numeric'
assign_labels(x, variable = NULL, values = NULL, ...)
## S3 method for class 'data.frame'
assign_labels(
x,
select = NULL,
exclude = NULL,
values = NULL,
ignore_case = FALSE,
regex = FALSE,
verbose = TRUE,
...
)
x |
A data frame, factor or vector. |
... |
Currently not used. |
variable |
The variable label as string. |
values |
The value labels as (named) character vector. If |
select |
Variables that will be included when performing the required tasks. Can be either
If |
exclude |
See |
ignore_case |
Logical, if |
regex |
Logical, if |
verbose |
Toggle warnings. |
A labelled variable, or a data frame of labelled variables.
select
argumentFor most functions that have a select
argument (including this function),
the complete input data frame is returned, even when select
only selects
a range of variables. That is, the function is only applied to those variables
that have a match in select
, while all other variables remain unchanged.
In other words: for this function, select
will not omit any non-included
variables, so that the returned data frame will include all variables
from the input data frame.
x <- 1:3
# labelling by providing required number of labels
assign_labels(
x,
variable = "My x",
values = c("one", "two", "three")
)
# labelling using named vectors
data(iris)
out <- assign_labels(
iris$Species,
variable = "Labelled Species",
values = c(`setosa` = "Spec1", `versicolor` = "Spec2", `virginica` = "Spec3")
)
str(out)
# data frame example
out <- assign_labels(
iris,
select = "Species",
variable = "Labelled Species",
values = c(`setosa` = "Spec1", `versicolor` = "Spec2", `virginica` = "Spec3")
)
str(out$Species)
# Partial labelling
x <- 1:5
assign_labels(
x,
variable = "My x",
values = c(`1` = "lowest", `5` = "highest")
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.