-1

I am very new to R programming, and I have a few datasets that I'm playing around with. One of the things I'm trying to do is use ggplot to graph what percentage of the population in each state voted in the 2016 election.

The first csv file I have contains an estimate of the population of each state in 2016, and the second csv file I have contains the number of votes cast by each party in the 2016 election. I'm not sure how to attach the file here, so I will show some screenshots:

2016 Election Votes: enter image description here

2016 State Populations: enter image description here

From what I understand, I can read the 2016 election votes csv file, and create a new column that contains the total votes using something like:

electionVotes$TotalVotes <- electionVotes$DemocraticCandidates + electionVotes$RepublicanCandidates + electionVotes$OtherCandidates

Once I have that, I would like to create a column where I do something like:

electionVotes$PercentVoted <- electionVotes$TotalVotes / *number of people per state*

I understand how to use ggplot to display the results, but what is confusing to me is how I can accurately use these tables with each other when one State column uses an abbreviation for the state name, like "AL", while the other one uses ".Alabama".

Any thoughts on what would be the best process to do this other than manually editing the csv file? Thank you!

Pecker
  • 133
  • 1
  • 9
  • Please read the information at the top of the [tag:r] tag home page and note in particular that reproducible examples are requested, not images. Anyone who wants to use your data would have to retype it all. – G. Grothendieck Feb 25 '21 at 16:17
  • With your data, first remove the "leading periods" from state name https://stackoverflow.com/q/46671796/10276092 , then see this answer https://stackoverflow.com/a/5412104/10276092 on matching state name and state abrv. – M.Viking Feb 25 '21 at 16:27

1 Answers1

0

You could bring in a table (http://app02.clerk.org/menu/ccis/Help/CCIS%20Codes/state_codes.html) that links the abbreviations to the full state names and use that to join the two datasets.

BEVAN
  • 426
  • 2
  • 12