Home > Software engineering >  Rename columns based on another DataFrame in R
Rename columns based on another DataFrame in R

Time:07-05

My column titles are not correct. I want to rename all my column of a matrix (because i have v1,v2,v3,..) according to data frame (the name of the first column corresponds to the first title of my data frame). I have to repeat this for my 39 columns. So the goal would be to do a for-loop.

df1 is the matrix that has to be changed.

for (i in 1:39) {
names(df1[,i]) <- names(dfnorm[,i])
}

This code is not working.

CodePudding user response:

If I understand correctly, this should work:

names(df1)[1:39] <- names(dfnorm)[1:39]
  • Related