6.4 Data challenge: African elephants

Our World in Data is an open-access project that publishes many datasets and charts about global challenges, for example energy, food, war, technological change etc. In this data challenge, we will analyse the data set on African elephant populations.

  1. Load the data set into R using the command elephants <- read.csv(url("https://runifr.netlify.app/web/african-elephants.csv"))

  2. Check the dimensions of the dataset: How many rows and columns are there?

  3. Identify the earliest and latest year in which data was collected

  4. How many times does the entity Central African Republic occur in this dataset?

  5. Create a boolean vector indicating whether or not the country code (Code) is missing.

  6. How many different entities are there?

  7. Rename the column African.Elephant.population..AfESG..2019. (weird name) to counts.

  8. Sort the column counts from smallest to largest. Which entities and years correspond to the minimum and maximum number of elephants?

  9. Add an extra column to the data frame that indicates whether the entity is a country or a region (Africa, Central Africa, Eastern Africa, Southern Africa, Western Africa).

  10. Calculate the median number of elephants across all entities for the year 2007.

  11. Extract the rows where the entity is Eastern Africa and where the number of African elephants is smaller than 100000.

  12. Extract the rows that correspond to the entity Africa and store them in a new data frame africanElephants. Add a new column to this data frame that calculates the fraction of elephants relative to the (estimated) number of elephants of the year 1500.

  13. The equator traverses the countries with the codes GAB, COD, UGA and KEN. Create two new entities named Equatorial counties with code NA for the years 2007 and 2015 and append them to the data frame. The number of African elephants per year is given by the sum of all elephants from these countries.