Kiezen tussen de vier werkwoorden
In dit hoofdstuk heb je geleerd over de vier werkwoorden: select(), mutate(), relocate() en rename(). Hier kies je het juiste werkwoord voor elke situatie. Je hoeft niets te wijzigen binnen de haakjes.
Deze oefening maakt deel uit van de cursus
Data manipulatie met dplyr
Oefeninstructies
- Kies het juiste werkwoord om de naam van de kolom
unemploymentte wijzigen naarunemployment_rate. - Kies het juiste werkwoord om alleen de kolommen
state,countyen de kolommen diepovertybevatten te behouden. - Bereken een nieuwe kolom
fraction_womenmet het aandeel vrouwen in de bevolking, zonder kolommen te verwijderen. - Behoud slechts drie kolommen:
state,countyenemployed / population, die jeemployment_ratezult noemen.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Change the name of the unemployment column
counties %>%
___(unemployment_rate = unemployment)
# Keep the state and county columns, and the columns containing poverty
counties %>%
___(state, county, contains("poverty"))
# Calculate the fraction_women column without dropping the other columns
counties %>%
___(fraction_women = women / population)
# Move the region column to before state
counties %>%
___(region, .before = state)