Summarizing the median life expectancy
You've seen how to find the mean life expectancy and the total population across a set of observations, but mean() and sum() are only two of the functions R provides for summarizing a collection of numbers. Here, you'll learn to use the median() function in combination with summarize().
By the way, dplyr displays some messages when it's loaded that we've been hiding so far. They'll show up in red and start with:
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
This will occur in future exercises each time you load dplyr: it's mentioning some built-in functions that are overwritten by dplyr. You won't need to worry about this message within this course.
This exercise is part of the course
Introduction to the Tidyverse
Exercise instructions
- Use the
median()function within asummarize()to find the median life expectancy. Save it into a column calledmedianLifeExp.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
library(gapminder)
library(dplyr)
# Summarize to find the median life expectancy