Skip to content

D'Hondt method

3 messages · Carlos J. Gil Bellosta, Thomas Steiner

#
Hello,

I believe that a "productionized" version of the following would do:

dHont <- function( candidates, votes, seats ){
    tmp <- data.frame(
                candidates = rep( candidates, each = seats ),
                scores     = as.vector(sapply( votes, function(x) x /
1:seats ))
                )
    tmp <- tmp$candidates[order( - tmp$scores )] [1:seats]
    table(tmp)
}
[1]  448 7685 5445  482 6266
tmp
a b c d e 
0 4 3 0 3 

Best regards,

Carlos J. Gil Bellosta
http://www.datanalytics.com
On Wed, 2009-02-04 at 12:16 +0100, Thomas Steiner wrote:
#
very cool, easier than I thought... (although I am not fully familiar
with sapply() and friends)

quick reality-check (no proof!) at
http://icon.cat/util/elections/isuHqUyDYh shows that the results
coincide:

votes <- c(42201,38635,247736,170627,48236,117151,61379,35889,92321)
dHont(c("BGLD","KTN","N?","O?","SLBG","STMK","T","VLBG","W"), votes, 26)

so thanks a lot, have a great day!

Thomas