I looked up a lot of similar questions on Stackoverflow but I could not locate the one I am asking.
Consider a dataset:
A B C D E F G
a b c d e f g
And mapping dataset to be: current desired
B H
C I
D J
E K
F L
namechangevector <- c('B', 'C', 'D', 'E', 'F')
I am using this command:
colnames(data[namechangevector]) <- as.character(mappingdata$desired[match(names(data[namechangevectors]), mappingdata$current)])
But, this doesn't work. However, this works:
colnames(data)[2:6] <- as.character(mappingdata$desired[match(names(data[namechangevectors]), mappingdata$current)])
But since, the vector can have more values and dataset can keep changing. I want to match using the vector and not the position. Please help!