Learn R Programming

FastUtils (version 0.2.1)

setNames: Set Names of an Object

Description

Improvement to stats::setNames() sets new names for an object, ensuring that the length of the new names matches the length of the object. Additionally, if the length of newNames is one, it is repeated to match the length of the object.

Usage

setNames(object, newNames)

Value

The object with updated names.

Arguments

object

An object.

newNames

A character vector specifying the new names.

Examples

Run this code
# Set new names for a vector
x <- c(1, 2, 3)
x <- setNames(x, c("A", "B", "C"))

# some syntactic sugar can be achieved with a special mutator
`%setNames%` <- createMutator(setNames)
x %setNames% c("D", "E", "F")

Run the code above in your browser using DataLab