setNames {FastUtils} | R Documentation |
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)
Arguments
object |
An object. |
newNames |
A character vector specifying the new names. |
Value
The object with updated names.
Examples
# 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")
[Package FastUtils version 0.2.1 Index]