Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

frename

Fast Renaming Objects


Description

A fast substitute for dplyr::rename. setrename renames objects by reference. These functions also work with objects other than data frames that have a 'names' attribute.

Usage

frename(.x, ..., cols = NULL)

setrename(.x, ..., cols = NULL)

Arguments

.x

an R object with a 'names' attribute.

...

either tagged vector expressions of the form name = newname, or a single function (+ optional arguments to the function) applied to all names (of columns/elements selected in cols).

cols

If ... is a function, select a subset of columns/elements to rename using names, indices, a logical vector or a function applied to the columns if .x is a data frame (e.g. is.numeric).

Value

.x renamed.

See Also

Examples

## Using tagged expressions
head(frename(iris, Sepal.Length = SL, Sepal.Width = SW,
                   Petal.Length = PL, Petal.Width = PW))
head(frename(iris, Sepal.Length = "S L", Sepal.Width = "S W",
                   Petal.Length = "P L", Petal.Width = "P W"))

## Using a function
head(frename(iris, tolower))
head(frename(iris, tolower, cols = 1:2))
head(frename(iris, tolower, cols = is.numeric))
head(frename(iris, paste, "new", sep = "_", cols = 1:2))

## Renaming by reference
setrename(iris, tolower)
head(iris)
rm(iris)

collapse

Advanced and Fast Data Transformation

v1.5.3
GPL (>= 2) | file LICENSE
Authors
Sebastian Krantz [aut, cre], Matt Dowle [ctb], Arun Srinivasan [ctb], Laurent Berge [ctb], Dirk Eddelbuettel [ctb], Josh Pasek [ctb], Kevin Tappe [ctb], R Core Team and contributors worldwide [ctb], Martyn Plummer [cph], 1999-2016 The R Core Team [cph]
Initial release
2021-03-05

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.