rename: Rename columns

Description Usage Arguments Value Examples

View source: R/rename.R

Description

rename() changes the names of individual variables using new_name = old_name syntax. rename_with() renames columns using a function.

Usage

1
2
3
rename(.data, ...)

rename_with(.data, .fn, .cols = everything(), ...)

Arguments

.data

A data.frame

...

For rename(): comma separated key-value pairs in the form of new_name = old_name to rename selected variables.

For rename_with(): additional arguments passed onto .fn.

.fn

A function() used to transform the selected .cols. Should return a character vector the same length as the input.

.cols

Columns to rename; defaults to all columns.

Value

A data.frame with the following properties:

Examples

1
2
3
4
5
6
rename(mtcars, MilesPerGallon = mpg)
rename(mtcars, Cylinders = cyl, Gears = gear)
mtcars %>% rename(MilesPerGallon = mpg)

rename_with(mtcars, toupper)
rename_with(mtcars, toupper, starts_with("c"))

poorman documentation built on March 28, 2021, 5:05 p.m.