Rename column titles

You often come across the following warning in R:

The following object(s) are masked from data

This is because two columns in different datasets have the same name. It is very easy to rename the column titles of a dataset. I have attached the names of a dataset with attach(). When I give the command names() I’ll see the title names. Say I want to rename the first column title I only have to typ:

names(data)[1]<-"changed name"

If I want to change the second column title I have to change the 1 into a 2. If I want to change all the names I can give the following command:

names(data)<-c("changed name 1","changed name 2","etc.")