dplyr (R)

dplyr is the tidyverse package for data manipulation. It provides a small set of verb functions — filter, select, mutate, arrange, summarise, group_by — that read like a grammar for transforming data frames.

R

dplyr replaces fiddly base-R subsetting with consistent, readable verbs. Each takes a data frame and returns a data frame, so they chain naturally with the pipe (%>% or |>): take a tibble, filter rows, mutate new columns, group, then summarise. The result reads almost like a sentence describing the analysis.

The core verbs are filter() (keep rows by condition), select() (choose columns), mutate() (add or change columns), arrange() (sort), summarise() (collapse to summary stats), and group_by() (define groups so summarise/mutate operate per group). join functions combine tables.

dplyr is the dominant data-wrangling tool in modern R, paired with ggplot2 for plotting and tidyr for reshaping. Its pipe-friendly design makes multi-step transformations clear and easy to read top to bottom.

Syntax

library(dplyr)
df %>% filter(x > 0) %>% group_by(g) %>% summarise(m = mean(x))

Examples

R — Filters mtcars to 4-cylinder cars, then averages their mpg.

library(dplyr)
mtcars %>%
  filter(cyl == 4) %>%
  summarise(avg_mpg = mean(mpg))

See also

Back to the Dictionary