Import the Gapminder Dataset

First, I imported the gapminder dataset from the gapminder package and used the glimpse function to view the dataset.

## Rows: 1,704
## Columns: 6
## $ country   <fct> "Afghanistan", "Afghanistan", "Afghanistan", "Afghanistan", …
## $ continent <fct> Asia, Asia, Asia, Asia, Asia, Asia, Asia, Asia, Asia, Asia, …
## $ year      <int> 1952, 1957, 1962, 1967, 1972, 1977, 1982, 1987, 1992, 1997, …
## $ lifeExp   <dbl> 28.801, 30.332, 31.997, 34.020, 36.088, 38.438, 39.854, 40.8…
## $ pop       <int> 8425333, 9240934, 10267083, 11537966, 13079460, 14880372, 12…
## $ gdpPercap <dbl> 779.4453, 820.8530, 853.1007, 836.1971, 739.9811, 786.1134, …

Filter and Organize the Data

Next, I filtered the dataset to only include data from the Americas and Europe in 1997. I then arranged the data by population in descending order and grouped it by continent. Then I selected the two least populous countries from each of the desired continents (Americas and Europe), transposed the data, and reordered the columns to match the desired order. I added row names to the table as well, adding “statistic” above population and life expectancy. Below is the data frame before formatting into the desired table:

##         statistic     Jamaica Trinidad and Tobago   Iceland Montenegro
## 1      population 2531311.000         1138101.000 271192.00 692651.000
## 2 life expectancy      72.262              69.465     78.95     75.445

Recreate the Desired Table

I recreated a table as close to this table as I could. I used the kable function to create the table and the kable_styling function to style it. I added the desired headers using the add_header_above function and used the column_spec function to italicize the first column. Lastly, I used the footnote function to add the desired footnote to the table.

Americas
Europe
statistic Jamaica Trinidad and Tobago Iceland Montenegro
population 2531311 1138101 271192 692651
life expectancy 72 69 79 75
Note: Population and life expectancy for the two least populous countries in Americas and Europe in 1997.