Calculation of the voter turnout difference between two votes
cross_fun.Rd
This function creates a table with the differences in turnout between two votes for every counting circle in the original data.
Arguments
- df
A table containing the municipality ID and voter turnout for various issues. Each column represents a specific issue, and the column names should correspond to the issue IDs (e.g., 'eidg1', 'kant2').
- issue1, issue2
A character vector specifying the name of the columns containing the voter turnout of the issues of interest (e.g., "eidg1", "kant2").
- geo_cols
The name of the geo-column containing an identifier of the counting circle.
Examples
testdata <- data.frame(
gemwkid = c(13,49,41,43,44),
eidg1 = c(60.90,61.18,65.27,55.36,57.68),
eidg2 = c(62.16,62.54,66.95,56.65,58.68),
kant1 = c(57.73,60.27,63.31,51.93,54.49)
)
cross_fun(testdata, "eidg1", "eidg2", "gemwkid")
#> gemwkid combination difference
#> 1 13 eidg1_eidg2 -1.26
#> 2 49 eidg1_eidg2 -1.36
#> 3 41 eidg1_eidg2 -1.68
#> 4 43 eidg1_eidg2 -1.29
#> 5 44 eidg1_eidg2 -1.00
# generate combinations
combinations <- as.data.frame(t(combn(c("eidg1", "eidg2", "kant1"), 2)))
# difference between columns named as the first combination
cross_fun(testdata, combinations$V1[1], combinations$V2[1], "gemwkid")
#> gemwkid combination difference
#> 1 13 eidg1_eidg2 -1.26
#> 2 49 eidg1_eidg2 -1.36
#> 3 41 eidg1_eidg2 -1.68
#> 4 43 eidg1_eidg2 -1.29
#> 5 44 eidg1_eidg2 -1.00