Get startedGet started for free

Arranging observations by life expectancy

You use arrange() to sort observations in ascending or descending order of a particular variable. In this case, you'll sort the dataset based on the lifeExp variable.

This exercise is part of the course

Introduction to the Tidyverse

View Course

Exercise instructions

  • Sort the gapminder dataset in ascending order of life expectancy (lifeExp).
  • Sort the gapminder dataset in descending order of life expectancy.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

library(gapminder)
library(dplyr)

# Sort in ascending order of lifeExp


  
# Sort in descending order of lifeExp

Edit and Run Code