Question

# Election fraud is in the news! The US recently held a national referendum - the subject of which is

very mysterious (and not all that important). The US Secretary of State posted the election results to its

web site. One of your colleagues collected a snapshot of the election results page and cleaned it up a bit. She

sent it to you via email as the le exercise.html. However, there is still some work to do to extract the data!

Updated results will likely be available by the time we evaluate your script, so focus on correct logic rather

than obtaining the exact numbers.

Examine the le and load the data into a data.frame in R. Complete the following tasks:

a. (6 pts) Get an overall count of yes and no votes. Store the number of yes votes in a variable named

total_yes, and store the number of no votes in a variable named total_no.

b. (7 pts) Count the number of cities in which the referendum passed. Store this number in a variable

named num_cities_passed.

c. (8 pts) Which city had the highest percentage of yes votes? How about the highest percentage of no

d. (8 pts) One sign of fraud might be that the total number of votes cast in a city exceeds the population

of that city. Generate a list of potentially fraudulent cities and store the list in the vector variable

fraudsters.

*I don't know how I'm supposed to be extracting the data. Below is my code, bu everything comes up as 0L or null. When I tried adding is.na or as.numeric, it only changed it to 1L.

Here's the HTML:

Here's my code:

#Exercise 4

library(rvest)

#4.a

total_yes <- sum((as.numeric(html_data\$vote_yes, is.na=TRUE))

total_no <- sum(html_data\$vote_no)

#4.b

num_cities_passed <- sum(html_data\$vote_yes > html_data\$vote_no)

#4.c

#4.d

X
5 Table
X
A IDSC4110_4s.pptx: IDSC 4110 ( x
IDSC - University of Minnesota X
[email protected] - x
+
X
K
. ..
i: Apps At MyU 'x Canvas : Carlson At Carlson Room Rese... =APO AX MyTime
A 2936 Ed Loan Group Study Spaces Grade Calculator &lt; IDSC 4110 @ Datacamp
city
state
BERKELEY
vote_yes
vote no
population
IL
8590
9863
SACO
15242
ME
8327
2113
HENDERSONVLLE
26399
NC
590
7906
12893
MAYAGUEZ
PR
370
BRENTWOOD
8526
21858
PA
3392
1556
23250
SCRANTON
PA
5113
6485
MANCHESTER
23367
NJ
4434
9103
17426
LINCOLN
IL
2292
1907
24026
PA
1046
1652
18833
DORA
AL
6253
FLORENCE
1830
25190
MA
5005
420
24915
IRVINGTON
NJ
7624
PARKER CITY
8738
29126
IN
5825
9419
24932
AZLE
TX
7271
9779
LONDON
21980
KY
3203
3171
25075
RAMSEUR
NC
9822
8275
18037
BASTROP
LA
6508
2708
MECHANICSVLLE
16240
VA
227
GROVELAND
4990
20038
MA
7234
6026
23326
BRAZEAU
MO
1655
MELBOURNE
2279
26971
FL
9243
7275
27794
NYACK
NY
6703
4899
HARTFORD
25267
AL
6266
724
MORRISVILLE
24102
NC
3735
7985
SOCORRO
23659
TX
9719
1187
ALBANY
29988
NY
7259
1009
GRAND RAPIDS
26533
MI
1283
7507
11933
Type here to search
o ed
9a
W
R
11:28 PM
9/30/2019

### Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

• ### -

Study Documents

Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

Browse Documents