Created
August 30, 2013 12:09
-
-
Save andilabs/6389216 to your computer and use it in GitHub Desktop.
R rename data frame columns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d <- data.frame(alpha=1:3, beta=4:6, gamma=7:9) | |
# alpha beta gamma | |
# 1 4 7 | |
# 2 5 8 | |
# 3 6 9 | |
names(d) | |
# "alpha" "beta" "gamma" | |
The simplest way is to use rename() from the plyr package: | |
rename(d, c("beta"="two", "gamma"="three")) | |
# alpha two three | |
# 1 4 7 | |
# 2 5 8 | |
# 3 6 9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment