Learn R Programming

misty (version 0.4.5)

df.rename: Rename Columns in a Matrix or Variables in a Data Frame

Description

This function renames columns in a matrix or variables in a data frame by specifying a character string or character vector indicating the columns or variables to be renamed and a character string or character vector indicating the corresponding replacement values.

Usage

df.rename(x, from, to, check = TRUE)

Arguments

x

a matrix or data frame.

from

a character string or character vector indicating the column(s) or variable(s) to be renamed.

to

a character string or character vector indicating the corresponding replacement values for the column(s) or variable(s) specified in the argument name.

check

logical: if TRUE, argument specification is checked.

Value

Returns a matrix or data frame with renamed columns or variables.

See Also

df.duplicated, df.unique, df.merge, df.rbind, df.sort

Examples

Run this code
# NOT RUN {
dat <- data.frame(a = c(3, 1, 6),
                  b = c(4, 2, 5),
                  c = c(7, 3, 1))

# Rename variable b in the data frame 'dat' to y
df.rename(dat, from = "b", to = "y")

# Rename variable a, b, and c in the data frame 'dat' to x, y, and z
df.rename(dat, from = c("a", "b", "c"), to = c("x", "y", "z"))
# }

Run the code above in your browser using DataLab