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.
Latihan ini adalah bagian dari kursus
Introduction to the Tidyverse
Petunjuk latihan
- Use
mutate()to change the existinglifeExpcolumn, by multiplying it by 12:12 * lifeExp. - Use
mutate()to add a new column, calledlifeExpMonths, calculated as12 * lifeExp.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
library(gapminder)
library(dplyr)
# Use mutate to change lifeExp to be in months
# Use mutate to create a new column called lifeExpMonths