Rename columns in a dataset

Hi, I,m trying to rename the columns in a dataframe for that i excute this sentence
rename(paa_codazzi, Codigo = ...1, Descripcion=...2,Fecha_inic = ...3)

apparently it works but when I tried to use the dataset with the new names the columns appear again with old names

You need to assign the renamed data frame to a new object.

For example:

library(dplyr)

# renamed, but not in any object
iris %>% 
  rename(sepal_length = Sepal.Length, sepal_width = Sepal.Width) %>% 
  head()

# assigned to new object
iris2 <- iris %>% 
  rename(sepal_length = Sepal.Length, sepal_width = Sepal.Width) %>% 
  head()

# new object
iris2

  sepal_length sepal_width Petal.Length Petal.Width Species
1          5.1         3.5          1.4         0.2  setosa
2          4.9         3.0          1.4         0.2  setosa
3          4.7         3.2          1.3         0.2  setosa
4          4.6         3.1          1.5         0.2  setosa
5          5.0         3.6          1.4         0.2  setosa
6          5.4         3.9          1.7         0.4  setosa

Thank you so much for your help

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.