Is there a shorter version for the folowing principle to rename certain columns of a data frame?
data1<-data.frame(\"a\"=1:3,\"b\"=1:3,\"c\"=1:3)
data1Names&
Use match
to replace selected elements and to respect the order when using names<-
...
names(data1)[ match( c("a", "c") , names(data1) ) ] <- c("hello", "world")
# hello b world
#1 1 1 1
#2 2 2 2
#3 3 3 3
Swapping the desired order of renaming...
names(data1)[ match( c("c", "a") , names(data1) ) ] <- c("hello", "world")
# world b hello
#1 1 1 1
#2 2 2 2
#3 3 3 3