salhin
salhin

Reputation: 2652

Change one column's name in R

I need to change a specific column name in R. I used the following command but it did not change anything.

colnames(mydata[3])<-"newname"

"3" is the column number

Upvotes: 2

Views: 1623

Answers (1)

nrussell
nrussell

Reputation: 18612

colnames(mydata)[3] <- "newname". colnames is a vector itself, so just move your [3] outside it.

Upvotes: 2

Related Questions