This functions takes votes in percent (per party) obtained from a survey, and returns a table containing votes (in percent) and party names. Conducts sanity checks along the way, such as checking that percentages add up to 1.
as_survey( percent, samplesize, parties = c("cdu", "spd", "gruene", "fdp", "linke", "piraten", "afd", "fw", "sonstige"), epsilon = 1e-05 )
percent | Votes in percent each party received in the survey
of interest. Can be set to |
---|---|
samplesize | Number of respondents in survey. |
parties | Vector of same length and in the same order as |
epsilon | The parameter |
A data.frame
containing input and absolute number of votes
in survey per party.
forsa <- as_survey( percent = c(0.41, 0.24, 0.13, 0.04, 0.08, 0.03, 0.03, 0.04), samplesize = 2508, parties = c("cdu/csu", "spd", "gruene", "fdp", "linke", "piraten", "afd", "others")) forsa#> party percent votes #> 1 cdu/csu 0.41 1028.28 #> 2 spd 0.24 601.92 #> 3 gruene 0.13 326.04 #> 4 fdp 0.04 100.32 #> 5 linke 0.08 200.64 #> 6 piraten 0.03 75.24 #> 7 afd 0.03 75.24 #> 8 others 0.04 100.32