-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabc_scraper.R
495 lines (483 loc) · 7.71 KB
/
abc_scraper.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
# devtools::install_github('milesmcbain/datapasta')
library(datapasta)
convert_abc <- function(x) {
matrix(x, ncol = 5, byrow = T) %>%
data.frame %>%
rename(
Party_ABC = X1,
Candidate = X2,
Votes = X3,
`Percent` = X4,
Swing = X5
) %>%
mutate_at(.vars = vars(Votes:Swing), .funs = parse_number) %>%
mutate_at(.vars = vars(Party_ABC, Candidate), .funs = parse_character) %>%
mutate(Candidate = substr(
Candidate,
start = 1,
stop = nchar(as.character(Candidate)) / 2
))
}
ABC_2CP <- list(
Algester = c(
"Labor",
"Leeanne EnochLeeanne Enoch",
"17,820",
"64.3%",
"+4.7%",
"LNP",
"Clinton PattisonClinton Pattison",
"9,876",
"35.7%",
"-4.7%"
)
,
Aspley = c(
"Labor",
"Bart MellishBart Mellish",
"16,376",
"51.2%",
"+4.3%",
"LNP",
"Tracy DavisTracy Davis",
"15,633",
"48.8%",
"-4.3%"
)
,
Bancroft = c(
"Labor",
"Chris WhitingChris Whiting",
"15,425",
"56.0%",
"-2.4%",
"LNP",
"Kara ThomasKara Thomas",
"12,144",
"44.0%",
"+2.4%"
)
,
`Barron River` = c(
"Labor",
"Craig CrawfordCraig Crawford",
"14,530",
"52.6%",
"-1.0%",
"LNP",
"Michael TroutMichael Trout",
"13,109",
"47.4%",
"+1.0%"
)
,
Bonney = c(
"LNP",
"Sam O'ConnorSam O'Connor",
"13,172",
"51.4%",
"-0.7%",
"Labor",
"Rowan HolzbergerRowan Holzberger",
"12,456",
"48.6%",
"+0.7%"
)
,
Broadwater = c(
"LNP",
"David CrisafulliDavid Crisafulli",
"18,041",
"68.7%",
"+2.4%",
"Labor",
"Peter FloriPeter Flori",
"8,202",
"31.3%",
"-2.4%"
)
,
Buderim = c(
"LNP",
"Brent MickelbergBrent Mickelberg",
"17,982",
"63.3%",
"+1.5%",
"One Nation",
"Steve DicksonSteve Dickson",
"10,437",
"36.7%",
"-1.5%"
)
,
Bulimba = c(
"Labor",
"Di FarmerDi Farmer",
"19,069",
"60.3%",
"+4.1%",
"LNP",
"Fiona WardFiona Ward",
"12,560",
"39.7%",
"-4.1%"
),
Bundaberg = c(
"LNP",
"David BattDavid Batt",
"16,051",
"54.2%",
"+4.7%",
"Labor",
"Leanne DonaldsonLeanne Donaldson",
"13,563",
"45.8%",
"-4.7%"
)
,
Bundamba = c(
"Labor",
"Jo-Ann MillerJo-Ann Miller",
"18,379",
"72.0%",
"-3.9%",
"LNP",
"Patrick HerbertPatrick Herbert",
"7,142",
"28.0%",
"+3.9%"
),
Burdekin = c(
"LNP",
"Dale LastDale Last",
"14,338",
"50.6%",
"+2.0%",
"Labor",
"Michael BrunkerMichael Brunker",
"13,974",
"49.4%",
"-2.0%"
)
,
Burleigh = c(
"LNP",
"Michael HartMichael Hart",
"15,035",
"55.3%",
"-0.1%",
"Labor",
"Gail HislopGail Hislop",
"12,138",
"44.7%",
"+0.1%"
)
,
Burnett = c(
"LNP",
"Stephen BennettStephen Bennett",
"17,526",
"61.0%",
"+4.4%",
"Labor",
"Lee HarveyLee Harvey",
"11,219",
"39.0%",
"-4.4%"
),
Cairns = c(
"Labor",
"Michael HealyMichael Healy",
"14,669",
"53.5%",
"-4.0%",
"LNP",
"Sam MarinoSam Marino",
"12,753",
"46.5%",
"+4.0%"
)
,
Callide = c(
"LNP",
"Colin BoyceColin Boyce",
"14,023",
"54.2%",
"-5.6%",
"One Nation",
"Sharon LohseSharon Lohse",
"11,848",
"45.8%",
"+5.6%"
)
,
Caloundra = c(
"LNP",
"Mark McArdleMark McArdle",
"15,488",
"53.7%",
"-1.0%",
"Labor",
"Jason HuntJason Hunt",
"13,369",
"46.3%",
"+1.0%"
),
Capalaba = c(
"Labor",
"Don BrownDon Brown",
"16,237",
"57.3%",
"+0.8%",
"LNP",
"Cameron LeafeCameron Leafe",
"12,081",
"42.7%",
"-0.8%"
)
,
Chatsworth = c(
"LNP",
"Steve MinnikinSteve Minnikin",
"15,466",
"52.9%",
"-0.4%",
"Labor",
"Paul KeenePaul Keene",
"13,758",
"47.1%",
"+0.4%"
)
,
Clayfield = c(
"LNP",
"Tim NichollsTim Nicholls",
"15,470",
"52.8%",
"-3.8%",
"Labor",
"Philip AnthonyPhilip Anthony",
"13,822",
"47.2%",
"+3.8%"
)
,
Condamine = c(
"LNP",
"Pat WeirPat Weir",
"19,146",
"59.4%",
"-7.8%",
"One Nation",
"Frank AshmanFrank Ashman",
"13,110",
"40.6%",
"+7.8%"
)
,
Cook = c(
"Labor",
"Cynthia LuiCynthia Lui",
"13,438",
"54.2%",
"-2.6%",
"One Nation",
"Jen SackleyJen Sackley",
"11,375",
"45.8%",
"+2.6%"
)
,
Coomera = c(
"LNP",
"Michael CrandonMichael Crandon",
"15,269",
"53.1%",
"-2.7%",
"Labor",
"Christopher JohnsonChristopher Johnson",
"13,461",
"46.9%",
"+2.7%"
)
,
Cooper = c(
"Labor",
"Kate JonesKate Jones",
"19,524",
"60.6%",
"+7.3%",
"LNP",
"Robert ShearmanRobert Shearman",
"12,674",
"39.4%",
"-7.3%"
),
Currumbin = c(
"LNP",
"Jann StuckeyJann Stuckey",
"14,663",
"53.2%",
"-2.5%",
"Labor",
"Georgi LeaderGeorgi Leader",
"12,902",
"46.8%",
"+2.5%"
),
Everton = c(
"LNP",
"Tim ManderTim Mander",
"17,600",
"55.0%",
"+2.9%",
"Labor",
"David GreeneDavid Greene",
"14,421",
"45.0%",
"-2.9%"
)
,
`Ferny Grove` = c(
"Labor",
"Mark FurnerMark Furner",
"15,541",
"54.7%",
"-0.6%",
"LNP",
"Nick ElstonNick Elston",
"12,869",
"45.3%",
"+0.6%"
)
,
Gaven = c(
"Labor",
"Meaghan ScanlonMeaghan Scanlon",
"13,413",
"50.9%",
"+3.6%",
"LNP",
"Sid CrampSid Cramp",
"12,949",
"49.1%",
"-3.6%"
)
,
Gladstone = c(
"Labor",
"Glenn ButcherGlenn Butcher",
"18,089",
"71.1%",
"+8.1%",
"One Nation",
"Amy LohseAmy Lohse",
"7,342",
"28.9%",
"-8.1%"
)
,
`Glass House` = c(
"LNP",
"Andrew PowellAndrew Powell",
"14,968",
"52.7%",
"+1.8%",
"Labor",
"Brent HampsteadBrent Hampstead",
"13,432",
"47.3%",
"-1.8%"
),
`Pine Rivers` = c(
"Labor",
"Nikki BoydNikki Boyd",
"18,106",
"55.8%",
"+1.6%",
"LNP",
"Chris ThompsonChris Thompson",
"14,356",
"44.2%",
"-1.6%"
)
,
`South Brisbane` = c(
"Labor",
"Jackie TradJackie Trad",
"15,100",
"54.7%",
"-9.1%",
"Greens",
"Amy MacMahonAmy MacMahon",
"12,498",
"45.3%",
"+9.1%"
)
,
Maiwar = c(
"Greens",
"Michael BerkmanMichael Berkman",
"15,889",
"52.3%",
"+5.3%",
"LNP",
"Scott EmersonScott Emerson",
"14,471",
"47.7%",
"-5.3%"
),
Noosa = c(
"Independent",
"Sandy Bolton",
"17,574",
"61.7%",
"+18.5%",
"LNP",
"Glen ElmesGlen Elmes",
"10,921",
"38.3%",
"-18.5%"
),
Nudgee = c(
"Labor",
"Leanne LinardLeanne Linard",
"19,122",
"64.9%",
"+5.7%",
"LNP",
"Debbie GlazeDebbie Glaze",
"10,336",
"35.1%",
"-5.7%"
)
,
Oodgeroo = c(
"LNP",
"Mark RobinsonMark Robinson",
"15,817",
"57.1%",
"+1.4%",
"Labor",
"Tony AustinTony Austin",
"11,878",
"42.9%",
"-1.4%"
)
) %>%
map_df(~ convert_abc(.x), .id = "Electorate")
library(purrr)
party_key <- list(LNP = "LNP",
Labor = "ALP",
Greens = "GRN",
`One Nation` = "ONP",
`Katter's Australia` = "KAP",
Independent = "IND") %>%
map(~ data.frame(Party = .x)) %>%
bind_rows(.id = "Party_ABC") %>%
mutate_all(parse_character)
ABC_2CP <- inner_join(ABC_2CP, party_key) %>%
group_by(Electorate) %>%
arrange(Electorate, Percent) %>%
mutate(group = 1:n())
write_csv(ABC_2CP, "Data/2CP_votes.csv")