I have the following data
data <- data.frame(c=1:5, ID=0,a=2,b=5:9)
naming <- data.frame(short=c("a","b","c", "d", "e"), long=c("aa","bb","cc", "dd", "ee"))
I would like to rename the columns in data frame data
from c,ID,b,a
to cc,ID,bb,aa
I tried:
colnames(data) <- naming[match(naming$short, colnames(data)),2]
but this does not work, as both vectors are not of the same length, further, I would like to keep the column names in data
, that are not in naming
.
Any suggestions? Basically its hlookup
function from Excel, but due to large data files I cannot do this in Excel.