First, we load the mtcars dataset into memory:

library(datasets)
data(mtcars)

Run the following code in your R console. You should be able to understand this code after Lecture 4.

library(tidyverse)
efficiency <- mtcars %>%
    as_tibble %>%
    transmute(
        mpg = mpg,
        cylinders = factor(cyl, ordered = is.ordered(c(4, 6, 8))),
        weight = wt * 1000,
        horsepower = hp,
        engine = factor(vs, levels = c(0,1), labels = c("V-shaped", "straight")),
        transmission = factor(am, levels = c(0,1), labels = c("automatic", "manual")),
        gears = factor(gear)
    )

You should see the following table:

efficiency
## # A tibble: 32 x 7
##      mpg cylinders weight horsepower engine   transmission gears
##    <dbl> <fct>      <dbl>      <dbl> <fct>    <fct>        <fct>
##  1  21   6           2620        110 V-shaped manual       4    
##  2  21   6           2875        110 V-shaped manual       4    
##  3  22.8 4           2320         93 straight manual       4    
##  4  21.4 6           3215        110 straight automatic    3    
##  5  18.7 8           3440        175 V-shaped automatic    3    
##  6  18.1 6           3460        105 straight automatic    3    
##  7  14.3 8           3570        245 V-shaped automatic    3    
##  8  24.4 4           3190         62 straight automatic    4    
##  9  22.8 4           3150         95 straight automatic    4    
## 10  19.2 6           3440        123 straight automatic    4    
## # … with 22 more rows