Skip to content
Prev 169192 / 398506 Next

D'Hondt method

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: