Skip to content

Instantly share code, notes, and snippets.

@romunov
Last active February 6, 2016 14:15
Show Gist options
  • Select an option

  • Save romunov/be7c93fb33ee97096648 to your computer and use it in GitHub Desktop.

Select an option

Save romunov/be7c93fb33ee97096648 to your computer and use it in GitHub Desktop.
rename column names given a data.frame of old and new values
xy <- data.frame(x = 1:3, y = letters[1:3], z = LETTERS[1:3])
chg <- data.frame(old = colnames(xy), new = toupper(colnames(xy)))
library(plyr)
colnames(xy) <- mapvalues(x = colnames(xy),
from = as.character(chg$old),
to = as.character(chg$new))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment