andilabs
8/30/2013 - 12:09 PM

R rename data frame columns

R rename data frame columns

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