Learn R Programming

collapse (version 1.3.1)

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 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 (i.e. is.numeric).

Value

x renamed.

See Also

Data Frame Manipulation, Collapse Overview

Examples

Run this code
# NOT RUN {
## Using tagged expressions
head(frename(iris, Sepal.Length = SL, Sepal.Width = SW,
                   Petal.Length = PW, Petal.Width = PW))
head(frename(iris, Sepal.Length = "S L", Sepal.Width = "S W",
                   Petal.Length = "P W", 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))

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

# }

Run the code above in your browser using DataLab