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

rename.vars

Remove or rename variables in a dataframe


Description

Remove or rename a variables in a data frame.

Usage

rename.vars(data, from="", to="", info=TRUE)
remove.vars(data, names="", info=TRUE)

Arguments

data

dataframe to be modified.

from

character vector containing the current name of each variable to be renamed.

to

character vector containing the new name of each variable to be renamed.

names

character vector containing the names of variables to be removed.

info

boolean value indicating whether to print details of the removal/renaming. Defaults to TRUE.

Value

The updated data frame with variables listed in from renamed to the corresponding element of to.

Author(s)

Code by Don MacQueen macq\@llnl.gov. Documentation by Gregory R. Warnes greg@warnes.net

See Also

Examples

data <- data.frame(x=1:10,y=1:10,z=1:10)
names(data)
data <- rename.vars(data, c("x","y","z"), c("first","second","third"))
names(data)

data <- remove.vars(data, "second")
names(data)

gdata

Various R Programming Tools for Data Manipulation

v2.18.0
GPL-2
Authors
Gregory R. Warnes, Ben Bolker, Gregor Gorjanc, Gabor Grothendieck, Ales Korosec, Thomas Lumley, Don MacQueen, Arni Magnusson, Jim Rogers, and others
Initial release
2017-06-05

We don't support your browser anymore

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