var_labels: Get or set variable labels

View source: R/var_labels.R

var_labelsR Documentation

Get or set variable labels

Description

Assign labels to describe variables in a data frame. Can be called on a single variable or full data, to assign or to read existing labels.

Usage

var_labels(x)

var_labels(x) <- value

Arguments

x

A vector or a data frame.

value

Character label(s) to assign.

Details

For a vector, this reads/writes a base-R "label" attribute. For a data frame, this reads/writes the "label" attribute of each column.

Value

- If x is a data frame: a named character vector with one entry per column (missing labels are returned as NA_character_). - Otherwise: a single character string (or NA_character_).

Examples

df <- data.frame(x = 1:3, y = 4:6)

# Set labels for all columns
var_labels(df) <- c("this is x", "this is y")
var_labels(df)

# Set a label for a single column
var_labels(df$x) <- "this is x"
var_labels(df$x)


statuser documentation built on April 25, 2026, 5:06 p.m.