rename: Return modified names of object

Description Usage Arguments Details Value Examples

Description

Return modified names of object

Usage

1
rename(x, mapping)

Arguments

x

Object whose names should be modified

mapping

Named character vector whose \"names\" attribute matches all, some, or none of the names of x and whose elements will be used to make up the new names of x.

Details

The rename function does not modify x and thereby avoids potentially expensive copies due to R's copy-on-modify semantics. Use names<- with the result of rename to change the names of x in a non-expensive way.

Note that mapping does not have to contain new values for all elements of names(x). If an element of names(x) is not among names(mapping), it will be unchanged. In particular, if mapping and x have no names in common, rename will return names(x). It is an error for names(mapping) to contain duplicate names. It is okay for mapping to contain a mixture of named and unnamed elements. Unnamed elements of x will never be renamed.

Value

Return a character vector that can be used with names<- to change the names of x.

Examples

1
2
rename(c(a = 1, b = 2, c = 3, 4, `9` = 9),
    c(a = "A", b = NA, "foo", g = "G", `9` = "nine"))

cbaumbach/miscFun documentation built on May 13, 2019, 1:48 p.m.