Aan de slagGa gratis aan de slag

Using mutate to change or create a column

Suppose we want life expectancy to be measured in months instead of years: you'd have to multiply the existing value by 12. You can use the mutate() verb to change this column, or to create a new column that's calculated this way.

Deze oefening maakt deel uit van de cursus

Introduction to the Tidyverse

Cursus bekijken

Oefeninstructies

  • Use mutate() to change the existing lifeExp column, by multiplying it by 12: 12 * lifeExp.
  • Use mutate() to add a new column, called lifeExpMonths, calculated as 12 * lifeExp.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

library(gapminder)
library(dplyr)

# Use mutate to change lifeExp to be in months


# Use mutate to create a new column called lifeExpMonths
Code bewerken en uitvoeren