Data Wrangling with dplyr

Interactive beginner R tutorial on dplyr: filter, select, mutate, arrange, group_by and summarise β€” the tidyverse verbs for reshaping data. Run real R in your browser.

Base R can reshape data, but dplyr makes it read like plain English β€” a handful of verbs cover most of the job. Everything below is a live R console β€” edit the code and press Run Code.

Watch: data wrangling with dplyr

The core verbs β€” filter, select, mutate, group_by and summarise β€” on the mtcars data.

Download the R script  Β·  β–Ά Practice in the playground β€” or edit and run each snippet below.

Note

The first Run Code installs dplyr into your browser session β€” give it 20–40 seconds. After that it’s instant.

filter() β€” keep rows

Keep only the rows that pass a test:

select() β€” keep columns

Trim a wide table down to the columns you name:

mutate() β€” add a column

Compute a new column from the others:

group_by() + summarise() β€” collapse groups

The heart of most analyses: one summary row per group:

Your turn


Next: The pipe (|>) β†’ β€” chaining these verbs into a readable flow.