Data Handling

Filter rows, pick columns, sort, and reshape your data with dplyr.

Load the Data

First, you have to load the data.

filter( )

Keep only rows where a condition is TRUE.

Filter based on one condition

Illustration of filtering batch A tablets

Filter based on multiple conditions

Illustration of filtering batch A tablets with a weight above 502 mg
TipAvailable Operators
  • == equal — is the value exactly this?
  • != not equal — exclude this value
  • > / < greater / less than — strictly above or below
  • >= / <= greater / less than or equal — includes the boundary value
  • & and — both conditions must be true
  • | or — at least one condition must be true
select( )

Keep only the columns you need.

Select columns by name

Illustration of selecting columns

Drop a column by name

Illustration of dropping a column
rename( )

Rename a column: rename(new_name = old_name).

Illustration of renaming a column
arrange( )

Sort rows by a column.

Ascending order

Illustration of arranging rows in ascending order

Descending order

Illustration of arranging rows in descending order
mutate( )

Add or transform columns. See the full mutate() reference page for details.

Illustration of adding a column with newly calculated values
Combining steps

Chain any number of operations with the pipe — each result flows into the next.

Illustration of combining steps with the pipe operator