Exercise

filter

The dplyr function filter is used to choose specific rows of the data frame to keep. Unlike select which is for columns, filter is for rows. For example you can show just the New York row like this:

filter(murders, state == "New York")

You can use other logical vectors to filter rows.

Instructions

100 XP
  • Use filter to show the top 5 states with the highest murder rates. After we add murder rate and rank, do not change the murders dataset, just show the result. Note that you can filter based on the rank column.