
# to specify multiple variables/columns, we simply add a comma after the first rename and keep going. grocerylist <- rename(weeds, coopers = "flowers", asahi = "species", vb = "soil", littlecreatures = "weeds") The easiest way is probably just to copy it and then remove the old variable: This is usually reasonably efficient even with large variables such as data. For demonstrating purposes, I am going to rename all the columns of weeds to nonsensical crap.

If you want to rename multiple columns, this is a pretty simple addition. # Again, if you run this by itself it will not save to your data frame, unless you direct it to your data frame variable using the <. # In the brackets we need to specify our data frame (weeds) followed by a second argument specifying the name we want for our column = the name we already have. Establishing crisp, clear column names is essential to keeping a large statistics project organized, especially if you are using a. rename() is the method available in the dplyr package, which is used to change the particular column name. To do this with dplyr (a tidyverse package) we simply use the following command: weeds <- rename(weeds, flowers = flowers.m3) Rename Column in R Dataframe using rename(). Trust me, when you spend an hour trying to fix a line of code only to find a single capital letter is missing, you will understand. Personally, this is my favourite function in R as I hate captials, fullstops and other annoying column name problems that slow down coding or generate errors.

The rename() function allows us to simply rename a column name within our data frame. This will happen ALOT with data you enter or obtain from others, as R converts any spaces to fullstops and people tend to capitilise most words.

Built with the "Learn" Theme using Hugo and Blogdownīy now, if you are like me, you are probably getting annoyed at writing “flowers.m3” or “species.richness” everytime you need to refer to one of those columns.
