The vote column in the dataset has a number that represents that country’s vote:
1 = Yes
2 = Abstain
3 = No
8 = Not present
9 = Not a member
One step of data cleaning is removing observations (rows) that you’re not interested in. In this case, you want to remove “Not present” and “Not a member”.
开始练习:
Load the dplyr package.
Print the votes table.
Filter out rows where the vote recorded is “not present” or “not a member”, leaving cases where it is “yes”, “abstain”, or “no”.
提示:
You’ll want to pipe (%>%) the votes table into a filter() step. Note that the condition vote <= 3 will keep the observations you want.
#Adding a year column
The next step of data cleaning is manipulating your variables (columns) to make them more informative.
In this case, you have a session column that is hard to interpret intuitively. But since the UN started voting in 1946, and holds one session per year, you can get the year of a UN resolution by adding 1945 to the session number.
Use mutate() to add a year column by adding 1945 to the session column.
HINT: The step will look like mutate(year = […]). In the […], put your calculation as described above
:
Adding a country column The country codes in the ccode column are what’s called Correlates of War codes. This isn’t ideal for an analysis, since you’d like to work with recognizable country names.
You can use the countrycode package to translate. For example:
library(countrycode)
countrycode(2, “cown”, “country.name”) [1] “United States”
countrycode(c(2, 20, 40), “cown”, “country.name”) [1] “United States” “Canada” “Cuba”
Load the countrycode package.
Convert the country code 100 to its country name.
Add a new country column in your mutate() statement containing country names, using the countrycode() function to translate from the ccode column. Save the result to votes_processed.
HINT You can do countrycode(ccode, “cown”, “country.name”) within your mutate to compute the country names.
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
vv
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
v
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
v
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
v
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
: