BaşlayınÜcretsiz Başlayın

Finding the lowest-income state in each region

You've been learning to combine multiple dplyr verbs together. Here, you'll combine group_by(), summarize(), and slice_min() to find the state in each region with the highest income.

When you group by multiple columns and then summarize, it's important to remember that the summarize "peels off" one of the groups, but leaves the rest on. For example, if you group_by(X, Y) then summarize, the result will still be grouped by X.

counties_selected <- counties %>%
  select(region, state, county, population, income)

Bu egzersiz

Data Manipulation with dplyr

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Calculate the average income (as average_income) of counties within each region and state (notice the group_by() has already been done for you).
  • Find the state with the lowest average_income in each region.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

counties_selected %>%
  group_by(region, state) %>%
  # Calculate average income
  ___
  # Find the lowest income state in each region
  ___
Kodu Düzenle ve Çalıştır