Get startedGet started for free

The rename verb

1. The rename verb

Often, rather than only selecting columns, we'll sometimes want to rename the ones we already have. We'll learn a new verb to do this: the rename() verb.

2. Select columns

Let's start with a selected version of the counties dataset. Suppose we decide that the column name "unemployment" is a little ambiguous, and we'd like to rename it to unemployment_rate for clarity.

3. Rename a column

We can do this by piping into the rename verb, then specifying unemployment_rate equals unemployment. Notice that the new column name goes on the left, and the old column name goes on the right. In the result, the column's name has been changed to unemployment_rate.

4. Combine verbs

There's actually another way that to choose new names for columns: we can do it as part of select(). Take a look at this variation on select. We choose the three columns state, county, and population, but we can also specify unemployment_rate equals unemployment. This produces the same result of renaming the column: it's like select and rename in one step.

5. Compare verbs

Notice the difference between select and rename. In select we need to name all the columns you want to keep along with renaming one or more of them. With rename, we can just pick one column whose name you want to change. The verb we choose will vary depending on the analysis and the dataset.

6. Let's practice!

Let's practice!