CommencerCommencer gratuitement

Calculate spread measures

Let's extend the powerful group_by() and summarize() syntax to measures of spread. If you're unsure whether you're working with symmetric or skewed distributions, it's a good idea to consider a robust measure like IQR in addition to the usual measures of variance or standard deviation.

Cet exercice fait partie du cours

Exploratory Data Analysis in R

Afficher le cours

Instructions

The gap2007 dataset that you created in an earlier exercise is available in your workspace.

  • For each continent in gap2007, summarize life expectancies using the sd(), the IQR(), and the count of countries, n(). No need to name the new columns produced here. The n() function within your summarize() call does not take any arguments.
  • Graphically compare the spread of these distributions by constructing overlaid density plots of life expectancy broken down by continent.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Compute groupwise measures of spread
gap2007 %>%
  group_by(___) %>%
  summarize(___,
            ___,
            ___)

# Generate overlaid density plots
gap2007 %>%
  ggplot(aes(x = ___, fill = ___)) +
  geom_density(alpha = 0.3)
Modifier et exécuter le code