Skip to content

Instantly share code, notes, and snippets.

@geofferyzh
Created April 16, 2012 20:51
Show Gist options
  • Save geofferyzh/2401428 to your computer and use it in GitHub Desktop.
Save geofferyzh/2401428 to your computer and use it in GitHub Desktop.
RinAction - R Data Manipulation - rename variables
#################################################
## Renaming variables ##
#################################################
# using the rename() function in the "reshape" package
install.packages("reshape")
library(reshape)
rename(leadership, c(manager = "managerID", date = "testDate"))
# using the names() function
names(leadership)
names(leadership)[2] <- "testDate"
names(leadership)[6:9] <- c("Var1","Var2","Var3","Var4")
names(leadership)[6:9] <- paste("Var",1:5,sep="")
names(leadership)
# using colnames() and rownames() functions
colnames(data) <- paste('prefix_',1:ncol(data),sep="")
rownames(data) <- data[,1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment