renameCol: Rename columns

View source: R/renameCol.r

renameColR Documentation

Rename columns

Description

Rename columns of a data.frame or matrix.

Usage

renameCol(x, old, new)

Arguments

x

A data.frame or matrix.

old

Character vector with names(s), or numeric vector of the indices of the column(s) you want to rename.

new

Character vector of new names.

Value

A data.frame or matrix.

Examples


x <- data.frame(old_x = 1:5, old_y = letters[1:5], old_z = LETTERS[1:5])
x
renameCol(x, c('old_y', 'old_z'), c('new_Y', 'new_Z'))
renameCol(x, c(2, 3), c('new_Y', 'new_Z')) # same as above

# Long way:
new <- c('new_Y', 'new_Z')
colnames(x)[match(c('old_y', 'old_z'), colnames(x))] <- new


adamlilith/omnibus documentation built on Sept. 23, 2024, 9:36 a.m.