SELECT selects columns
The first verb is select. Let's use it to select some columns.
For this tutorial I'm mainly interested in Life expectancy, and child and adult mortality figures. For comparison let's also get the population size, GDP, and whether the country is treated as a developing or developed nation.
Simple:
(
data
%>% select(
Country, Year, Status,
`Life expectancy`, `infant deaths`, `under-five deaths`, `Adult Mortality`,
Population, GDP
)
)
Way to select!
Note
The `backticks` are needed there because of the spaces in the column names. Using `backticks` instead of "quotes" makes R interpret them as column names, as opposed to string values.
Renaming columns
However, aren't you a bit annoyed by those column names? I mean some have Capital letters, some are all lower case - and some have spaces in them.
Luckily select has a super power that can help us: it can rename columns too. Let's try:
(
data
%>% select(
country = Country,
year = Year,
status = Status,
population_size = Population,
life_expectancy = `Life expectancy`,
infant_deaths = `infant deaths`,
under_five_deaths = `under-five deaths`,
adult_deaths = `Adult Mortality`,
gdp_per_capita = GDP
)
)