# knesset22 by knesset size.R rm(list=ls()) knesset22=data.frame(party=c("likud", "bluewhite", "meshutefet", "shas", "aguda", "liberman", "yamina", "avoda", "democrats"), votes=c(1113617, 1151214, 470211, 330199, 268775, 310154, 260655, 212782, 192495)) # surplus agreements # likud + yamina # bluewhite + liberman # shas + aguda # avoda + democrats suragg=function(k){ # k=knesset0 sagg=k sagg$party=as.character(sagg$party) # likud + yamina w1=which(sagg$party=="likud") w2=which(sagg$party=="yamina") sagg$party[w1]="likud + yamina" sagg$mandats[w1]=sagg$mandats[w1]+sagg$mandats[w2] sagg$votes[w1]=sagg$votes[w1]+sagg$votes[w2] sagg=sagg[-w2,] # bluewhite + liberman w1=which(sagg$party=="bluewhite") w2=which(sagg$party=="liberman") sagg$party[w1]="bluewhite + liberman" sagg$mandats[w1]=sagg$mandats[w1]+sagg$mandats[w2] sagg$votes[w1]=sagg$votes[w1]+sagg$votes[w2] sagg=sagg[-w2,] # shas + aguda w1=which(sagg$party=="shas") w2=which(sagg$party=="aguda") sagg$party[w1]="shas + aguda" sagg$mandats[w1]=sagg$mandats[w1]+sagg$mandats[w2] sagg$votes[w1]=sagg$votes[w1]+sagg$votes[w2] sagg=sagg[-w2,] # avoda + democrats w1=which(sagg$party=="avoda") w2=which(sagg$party=="democrats") sagg$party[w1]="avoda + democrats" sagg$mandats[w1]=sagg$mandats[w1]+sagg$mandats[w2] sagg$votes[w1]=sagg$votes[w1]+sagg$votes[w2] sagg=sagg[-w2,] return(sagg) } baderofer=function(kn){ # kn=knesset0 sa=suragg(kn) kn$pay=kn$votes/(1+kn$mandats) sa$pay=sa$votes/(1+sa$mandats) w=which(sa$pay==max(sa$pay)) # likud + yamina if(sa$party[w]=="likud + yamina"){ w1=which(kn$party=="likud") w2=which(kn$party=="yamina") if(kn$pay[w1]>kn$pay[w2]){ kn$mandats[w1]=kn$mandats[w1]+1 } if(kn$pay[w1]kn$pay[w2]){ kn$mandats[w1]=kn$mandats[w1]+1 } if(kn$pay[w1]kn$pay[w2]){ kn$mandats[w1]=kn$mandats[w1]+1 } if(kn$pay[w1]kn$pay[w2]){ kn$mandats[w1]=kn$mandats[w1]+1 } if(kn$pay[w1]