Skip to main content
Module 4 · Lesson 1 of 27/18 in the course~20 min
Module lessons (1/2)

Filter, Select and Sort with dplyr

Lesson preview7 hands-on exercises readyCourse R · Module 4 — Tidyverse and Pipeline dplyr

Concatenate select(), filter(), and arrange(desc()) with the pipe operator %>% to extract and sort records.

What you'll learn in this lesson

  • Read and write sequential pipelines with the pipe operator %>% (and the native pipe |> introduced in R 4.1).
  • Select and exclude columns declaratively with select().
  • Filter lines with readable predicates via filter() (without having to repeat df$ or worry about NA).
  • Sort records ascending or descending with arrange() and desc().

Overview

In Base R, combining filtering, column choosing, and sorting often results in reverse-nested parentheses (arrange(select(filter(df, ...)))) that are difficult to read. The dplyr package (heart of the Tidyverse) solves the problem with clear verbs and the pipe (%>%) operator.

The pipe takes the result of the expression on the left and automatically passes it as the first argument of the function on the right:

Sections covered in this lesson

  1. 1How the Pipe works (%>% and |>)
  2. 2Test yourself: guided exercises
  3. 3Concept check
Pro Lesson · Module 4 — Tidyverse and Pipeline dplyr

Unlock "Filter, Select and Sort with dplyr" and the full Course R curriculum

Concatenate select(), filter(), and arrange(desc()) with the pipe operator %>% to extract and sort records.

Unlock all 7 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Course R plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.