เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

Breaking it down by province

Although the overall vote totals are the most important, you can dig deeper into this data by utilizing the geographic information. In this exercise, you'll see how the results differed by province.

Did Ahmadinejad win throughout the country, or were there provinces where the second place candidate came out on top? To answer this question, start by creating a province-level dataset.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Inference for Categorical Data in R

ดูคอร์ส

คำแนะนำการฝึกหัด

  • Start with iran, group by province, then summarize with two variables: the sum of the votes of the first place candidate and the sum of the votes of the second place candidate. Name each new column with the name of the candidate.
  • Inspect province_totals.
  • Filter province_totals for every row where the second-place candidate got more votes than the first-place candidate.

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Construct province-level dataset
province_totals <- ___ %>%
  # Group by province
  ___ %>%
  # Sum up votes for top two candidates
  ___ 

   
# Inspect data frame
province_totals

# Filter for won provinces won by #2
___ %>%
  ___(___ > ___)
แก้ไขและรันโค้ด