1. Learn
  2. /
  3. Courses
  4. /
  5. Inference for Categorical Data in R

Exercise

Who won?

The iran dataset contains all of the votes cast in this election, meaning that you can find the victor by computing the total number of votes for each candidate. In addition to answering the question of who won nationwide, you can also see how the results differed by province.

Along the way, you'll use a very useful function called gather(). This allows you to reshape your data frame by taking information stored in variable names and moving it to live in its own column.

Instructions 1/3

undefined XP
    1
    2
    3
  • Using the iran data, compute the total votes for each candidate by summarize()ing each of the candidate count columns with their sum. Name each new column with the name of the candidate.
  • Print totals to your screen.