VOOZH about

URL: https://www.geeksforgeeks.org/r-language/subset-data-frames-using-logical-conditions-in-r/

⇱ Subset Data Frames Using Logical Conditions In R - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Subset Data Frames Using Logical Conditions In R

Last Updated : 21 Jul, 2025

Subset Data Frames Using Logical Conditions in R programming language means selecting specific rows from a data frame where certain logical conditions are true, such as values being greater than, less than or equal to a given number.

1. Subset data frame with ==

This method subsets rows where the column value is equal to a specific value.

Output:

👁 subset
Output

2. Subset Data Frame with %in%

This method subsets rows where a column's value matches any value in a vector.

Output:

👁 subset
Output

3. Subset Data Frame with !=

This method subsets rows where the column value is not equal to a specific value.

Output:

👁 subsetting
Output


4. Subset Using Square Brackets [ ]

This is a base R approach to subset rows using logical conditions directly within square brackets.

Output:

👁 dataframe
Output

5. Subset Using subset() Function

The subset() function is a cleaner and more readable way to apply conditions on data frames.

Output:

👁 dataframe
Output

We learned about how to perform subsetting by using logical conditions.

Comment

Explore