Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

use R as coding language (a) Pseudocode (or outline) a function that inputs a matrix of ranked choice votes and returns a matrix of results.

use R as coding language

image text in transcribed
(a) Pseudocode (or outline) a function that inputs a matrix of ranked choice votes and returns a matrix of results. (b) Write a function called tally_rev() that inputs a matrix of ranked choice votes and returns a matrix of results. . Your tally_rev () function must be able to handle any number of choices/ candidates and any number of voters. . The column names of the output matrix must be the names of the choices/ candidates. . The row names of the output matrix must correspond to the appropriate round numbers. . If there is a tie for last place in a round, you must eliminate candidates in the following manner: If the tie occurs in the first round, eliminate the tied candidate who comes last alphabetically by first name. In any subsequent round: * If the sum of the the tied candidates votes is less than the number of votes for the next lowest candidate, eliminate both of the tied candidates. * Eliminate the tied candidate with the least votes in the previous round. Hint 1: In addition to the lecture notes, you may use the order () and/or rank () functions, if necessary. The order () function inputs a vector and outputs the indices of the input vector that will return the sorted values. The rank () function inputs a vector and outputs the relative rank of each element. Hint 2: It may be helpful to consider eliminating a candidate by setting all of their ranks to Inf. (c) It is Election Day in Pawnee! Use your tally_rev() function on the votes data and print the results using the function knitr: :kable (). The knitr: : kable () function will print the output matrix in a well-formatted table after knitting your file

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

A First Course In Differential Equations With Modeling Applications

Authors: Dennis G Zill

11th Edition

1337515574, 9781337515573

More Books

Students also viewed these Mathematics questions