I'm a complete newbie and am trying to change column names of a dataset in R. For example, to change the column name of 'Eth' in dataset quine to 'Ethnic'. Any help or the name of the function is greatly appreciated.
Asked
Active
Viewed 2.4k times
1 Answers
5
The function 'colnames' is what you're looking for
let's say that 'Eth' is the third column, do
colnames(dataset)[3]<-"Ethnic"
colnames(dataset) returns exactly what you think it should, but you can also use it to set column names.
Doing the following
colnames(dataset)<-newColNames
where newColNames is a vector of names of the same length as the number of columns in dataset will change all the column names in order.
The following (as I did above)
colnames(dataset)[i]<-name
where name is a string and i is an integer, will change the name of the ith column to whatever the string "name" is

DMT
- 1,577
- 10
- 16