| var_labels | R Documentation |
Retrieve or assign labels for all variables (columns) in a dataset.
var_labels(
x,
unlist = FALSE,
null_action = c("keep", "fill", "skip", "na", "empty")
)
var_labels(x) <- value
x |
A |
unlist |
Logical; if |
null_action |
How to handle columns without labels. One of:
|
value |
|
This is the dataset-level equivalent of var_label().
It works with any data.frame-like object, including dataset_df(), and
returns/sets the "label" attribute of each column.
Labels are useful for storing human-readable descriptions of variables that may have short or cryptic column names.
For internal purposes, this function uses the "var_labels" dataset
attribute and delegates to var_label() and
var_label<-() on individual columns.
Getter: a named list (or vector if unlist = TRUE) of variable labels.
Setter: the modified x with updated labels, returned invisibly.
var_label()
Other defined metadata methods and functions:
var_label(),
var_namespace(),
var_unit()
df <- dataset_df(
id = defined(1:3, label = "Observation ID"),
temp = defined(c(22.5, 23.0, 21.8), label = "Temperature (°C)"),
site = defined(c("A", "B", "A"))
)
# Get all variable labels
var_labels(df)
# Set multiple labels at once
var_labels(df) <- list(site = "Site code")
# Return as a named vector with empty string for unlabeled vars
var_labels(df, unlist = TRUE, null_action = "empty")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.