Een landkolom toevoegen
De landcodes in de kolom ccode zijn de zogeheten Correlates of War-codes. Dat is niet ideaal voor een analyse, want je werkt liever met herkenbare landnamen.
Je kunt het pakket countrycode gebruiken om te vertalen. Bijvoorbeeld:
library(countrycode)
# Vertaal de landcode 2
> countrycode(2, "cown", "country.name")
[1] "United States"
# Vertaal meerdere landcodes
> countrycode(c(2, 20, 40), "cown", "country.name")
[1] "United States" "Canada" "Cuba"
Deze oefening maakt deel uit van de cursus
Casestudy: Exploratory Data Analysis in R
Oefeninstructies
- Laad het pakket
countrycode. - Zet landcode 100 om naar de bijbehorende landnaam.
- Voeg een nieuwe kolom
countrytoe in jemutate()-statement met landnamen, waarbij je de functiecountrycode()gebruikt om te vertalen vanuit de kolomccode. Sla het resultaat op invotes_processed.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Load the countrycode package
# Convert country code 100
# Add a country column within the mutate: votes_processed
votes_processed <- votes %>%
filter(vote <= 3) %>%
mutate(year = session + 1945)