BAuisdhao
BAuisdhao

Reputation: 1

Renaming a variable name in r

I want to rename a column but, after running the code without errors, it doesn't change. The second variable of the data frame is 'Latest Name' and I want to change it to 'Name'.

Then I run:

rename(companies_names_industries, Name = 'Latest Name')

As you see below, the name has changed:

enter image description here

But then I check it again listing the variables names.

names(companies_names_industries)

And It is still the same, as you can see here:

enter image description here

Why does this happen? And how can I definitely change the name of the variable?

Upvotes: 0

Views: 6049

Answers (1)

Mike
Mike

Reputation: 4400

you have to assign the data.frame to an object. your code will run but doesn't store it.

try:

library(dplyr)
df <- rename(companies_names_industries, Name = 'Latest Name')
names(df)

Upvotes: 1

Related Questions