Learn R Programming

sjmisc (version 2.3.0)

var_rename: Rename variables

Description

This function renames variables in a data frame, i.e. it renames the columns of the data frame.

Usage

var_rename(x, ...)

Arguments

x
Variable (vector), list of variables or a data frame where variables labels should be added as attribute. For var_labels(), x must be a data frame only.
...
Pairs of named vectors, where the name equals the variable name, which should be labelled, and the value is the new variable label.

Value

x, with new column names for those variables specified in ....

Examples

Run this code
# Set variable labels for data frame
dummy <- data.frame(a = sample(1:4, 10, replace = TRUE),
                    b = sample(1:4, 10, replace = TRUE),
                    c = sample(1:4, 10, replace = TRUE))

var_rename(dummy, a = "first.col", c = "3rd.col")

Run the code above in your browser using DataLab