1.9 Creating/Recoding variables

The dplyr::mutate function allows you to create new variables or transform existing ones.

library(dplyr)
data("starwars") 

# convert height in centimeters to inches, 
# and mass in kilograms to pounds
newdata <- mutate(starwars, 
                  height = height * 0.394,
                  mass   = mass   * 2.205)