my_gapminder: Gapminder data.

Description Usage Format Source See Also Examples

Description

Excerpt of the Gapminder data on life expectancy, GDP per capita, and population by country. This data and documentation come from the gapminder package, available as gapminder.

Usage

1

Format

The main data frame gapminder has 1704 rows and 6 variables:

country

factor with 142 levels

continent

factor with 5 levels

year

ranges from 1952 to 2007 in increments of 5 years

lifeExp

life expectancy at birth, in years

pop

population

gdpPercap

GDP per capita (US$, inflation-adjusted)

The supplemental data frame gapminder_unfiltered was not filtered on year or for complete data and has 3313 rows.

Source

http://www.gapminder.org/data/

See Also

country_colors for a nice color scheme for the countries

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
str(my_gapminder)
head(my_gapminder)
summary(my_gapminder)
table(my_gapminder$continent)
aggregate(lifeExp ~ continent, my_gapminder, median)
plot(lifeExp ~ year, my_gapminder, subset = country == "Cambodia", type = "b")
plot(lifeExp ~ gdpPercap, my_gapminder, subset = year == 2007, log = "x")

if (require("dplyr")) {
my_gapminder %>%
  filter(year == 2007) %>%
  group_by(continent) %>%
  summarise(lifeExp = median(lifeExp))

# how many unique countries does the data contain, by continent?
my_gapminder %>%
  group_by(continent) %>%
  summarize(n_obs = n(), n_countries = n_distinct(country))

# by continent, which country experienced the sharpest 5-year drop in
# life expectancy and what was the drop?
my_gapminder %>%
  group_by(continent, country) %>%
  select(country, year, continent, lifeExp) %>%
  mutate(le_delta = lifeExp - lag(lifeExp)) %>%
  summarize(worst_le_delta = min(le_delta, na.rm = TRUE)) %>%
  filter(min_rank(worst_le_delta) < 2) %>%
  arrange(worst_le_delta)
}

Chaos-Gao/MyStat302Package documentation built on March 20, 2021, 2 p.m.