Exercise

dplyr

Load the dplyr package and the murders dataset.

library(dplyr)
library(dslabs)
data(murders)

You can add columns using the dplyr function mutate. This function is aware of the column names and inside the function you can call them unquoted. Like this:

murders <- mutate(murders, population_in_millions = population / 10^6)

Note that we can write population rather than murders$population. The function mutate knows we are grabing columns from murders.

Instructions

100 XP
  • Use the function mutate to add a murders column named rate with the per 100,000 murder rate.
  • Make sure you redefine murders as done in the example code above.

Remember the murder rate is defined as the total murders divided by the population size times 100,000.