Renaming columns

select(my_data_frame, column_one, column_two, ...)
select(my_data_frame, new_column_name = current_column, ...)
select(my_data_frame, column_start:column_end)
select(my_data_frame, index_one, index_two, ...)
select(my_data_frame, index_start:index_end)
View Interactive Version

In addition to defining the columns we want keep, we can also rename them. To do this, we need to set the new column name inside the select() function using the command

new_column_name = current_column

In the following example, we select the columns year, state and total_votes but rename the year column to Election in the output:

select(pres_results, Election = year, state, total_votes)
# A tibble: 561 x 3
  Election state total_votes
     <dbl> <chr>       <dbl>
1     1976 AK         123574
2     1976 AL        1182850
3     1976 AR         767535
# … with 558 more rows
Select columns from a data frame