my_rename_fn: Renaming multiple columns using an external table of old-new...

View source: R/my_rename_fn.R

my_rename_fnR Documentation

Renaming multiple columns using an external table of old-new names

Description

Renaming columns is easy enough, but if you want to rename a bunch of them and you don't have a clear pattern, it can be kind of a pain. This function allows you to take an existing data frame and rename using a separate spreadsheet of names.

Usage

my_rename_fn(x, old_names, new_names)

Arguments

x

The dataframe or tibble whose names you want to change.

old_names

A vector of any names you want to change.

new_names

A vector of the new names you want x to take.

Details

The most common usage of this would be to import an excel sheet in which you have manually matched old_names and new_names. Thus it is important that the two vectors are of the same length and that each value in old_names matches up with the corresponding value in new_names.

Value

x, renamed as requested.

Examples

x <- tibble(a = c(1,2,3), b = c(2,3,4), c = c(3,4,5))
r <- tibble(old_names = c("a","b","d"), new_names = c("a.new", "b.new", "d.new"))
my_rename_fn(x, r$old_names, r$new_names)

Ingenuity-Inc/artlookR documentation built on May 18, 2022, 12:33 a.m.