'How can I change column names in R in imported dataset so they don't just show on console but are permanent?

// I was trying to rename my column using rename() but it only shows up in console but not in the dataset itself when I View() it.

daily_intensities%>%
  rename(NotActive=SedentaryMinutes)
View(daily_intensities)

After View() it still shows SedentaryMintues.

r


Solution 1:[1]

You can put the new column labels in list like so and pass it to the colnames:

colnames(df) <- c('newName1','newName2','newName3')

Or if its just one column:

names(df)[names(df) == 'oldName1'] <- 'newName1'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1