Package: dplyr


Function: rename()


Note: The dplyr::rename() formula is new value=old value, this is opposite of dplyr::recode().


1. Change the name of Var2

Review the data (d1)

# A tibble: 3 x 3
  Var1   Var2  Var3
  <chr> <dbl> <dbl>
1 a         2   3.6
2 b        NA   8.5
3 c         3  NA  

Change Var2 to grade

  • Note: Quotes are not required around variable names. If your variable names have spaces in them, you will need to put backticks around the variable name (ex: `Var 2`)
d1 %>% 
  dplyr::rename(grade = Var2)
# A tibble: 3 x 3
  Var1  grade  Var3
  <chr> <dbl> <dbl>
1 a         2   3.6
2 b        NA   8.5
3 c         3  NA  

If you wanted to change names of more than one variable you can just keep adding more variables.

d1 %>% 
  dplyr::rename(grade = Var2, score = Var3)
# A tibble: 3 x 3
  Var1  grade score
  <chr> <dbl> <dbl>
1 a         2   3.6
2 b        NA   8.5
3 c         3  NA  

Return to Name Variables