Created
December 9, 2013 19:25
-
-
Save ramnathv/7879235 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(RCurl) | |
url = getURL("https://raw.github.com/tcrug/ranked-choice-vote-data/master/2013-mayor-cvr.csv") | |
vote = read.csv(text = url, stringsAsFactors = F) | |
vote = vote[ , 2:4] | |
vote[vote == "undervote"] = NA | |
vote[vote == "overvote"] = NA | |
names(vote) = paste('choice', 1:3, sep = "_") | |
vote2 = apply(vote, 1, as.list) | |
find_loser <- function(l){ | |
l1 = sapply(l, '[[', 'choice_1') | |
attr(which.min(table(l1)), 'names') | |
} | |
slide_choices <- function(l, loser){ | |
lapply(l, function(x){ | |
x2 = Filter(function(y) !(y == loser), x) | |
return(x2) | |
}) | |
} | |
replace_loser <- function(l, loser){ | |
l[l == loser] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment