Filter Rows Based on Conditions in a Data Frame in R
- R-PROGRAMMING
There are multiple ways to filter rows based on condition in R data frame.
The following methods show how you can do it with syntax.
Method 1: Use filter() Function
library(dplyr) df %>% filter(column > n) Method 2: Use Logical Indexing
df[df$column > n, ] Method 3: Use subset() Function
subset(df, column > n) The following examples show how to filter rows based on condition in a dataframe.
Using filter() Function Let’s see how we can use filter() function from dplyr package: