renameCol | R Documentation |
Rename columns of a data.frame
or matrix
.
renameCol(x, old, new)
x |
A |
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. |
A data.frame
or matrix
.
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.