Question: 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

(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
Get step-by-step solutions from verified subject matter experts
