VOOZH about

URL: https://www.geeksforgeeks.org/r-language/filter-rows-based-on-conditions-in-a-dataframe-in-r/

⇱ Filter Rows Based on Conditions in a DataFrame in R - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Filter Rows Based on Conditions in a DataFrame in R

Last Updated : 21 Jul, 2025

To filter rows in a data frame using R, we can apply conditions directly to the columns. R offers several ways to perform this, depending on whether the condition is single or multiple.

1. Filter Rows Based on a Single Condition

This method filters rows where a specific condition is applied to a single column.

Example: Filter rows where id > 400

Output:

👁 data
Output

Example: Filter rows where age > 35

Output:

👁 dataframe
Output

2. Filter Rows Based on Multiple Conditions

This method filters rows where multiple conditions are checked using logical operators like &, | or %in%.

Example: Filter rows where age > 30 and id == 450

Output:

👁 dataframe
Output

Example: Filter rows where name is "b" or "e"

Output:

👁 data
Output

We learned about how to filter rows based on conditions in a data frame.

Comment

Explore