I had some grand ideas of microbenchmarking each of these methods to find the fastest renaming solution, and maybe that will happen someday if I get an espresso machine or something. Coming from SPSS, I was previously familiar with rename and just left it at that. # "miles_g" "cylinder" "disp" "hp" "drat" "wt" What’s in a (re)name R is an amazing language and there are endless things you can do. If(!require(dplyr)) #rename "mpg" and "cyl" column names in mtcars
)įor example, here is how to rename the “mpg” and “cyl” column names in the mtcars dataset: #install (if not already installed) and load dplyr package Names(mtcars) % rename(new_name1 = old_name1, new_name2 = old_name2.
To rename the first 4 columns, we can use the following syntax: #rename first 4 columns I saved all that code we wrote to import it, renaming columns, and joining values and labels into an R script: importmurders.R. There are a total of 11 column names in mtcars: #view column names of mtcars Renaming the First n Columns Using Base R