This post covers how to change variable names in R Studio.
1. Preparation
We will use rename() function in dplyr package, so install the package and load it.
install.packages("dplyr") #installing dplyr library(dplyr) #loading dplyr
Also, it is always wise to make a copy of the original data frame before changing the variable names.
new df name <- original df name #syntax structure df1 <- df_raw #example
2. Changing Variable Names
Now we use rename() function.Basically we are changing the data frame, but only the content, a variable in this case, so the name of the data frame does not have to be changed.
The exmaple below means that I changed the name of the variable from 'sex' to 'gender' in a data frame named 'df1'.
df name <- rename(df name, new v name = original v name) #syntax structure df1 <- rename(df1, gender = sex) #example
(Thumbnail image: photo by Markus Spiske on Unsplash)
 
![[R] Data Import](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5c_zi7m6ac3-R1bYIJyT3W6OQT7hc_EM4VLG7AGHx4KTh34WM1TNnGdU5Ft1mTclDmN1_U91hHixDjM1FFnGa8bZYnpykFWAMGv_EBKXyrWWjrPcxOc25YzY50igIPuznUsEyWRlvjKJpbO6EOCAn3GPlHE3wg2QSOLiqbkLfUazVALtPSH93WE3CTw/w72-h72-p-k-no-nu/mika-baumeister-Wpnoqo2plFA-unsplash.jpg) 
0 Comments