How to apply multiple filters on multiple columns using multiple conditions in R?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

How to apply multiple filters on multiple columns using multiple conditions in R?

How to apply multiple filters on multiple columns using multiple conditions in R?

This recipe helps you apply multiple filters on multiple columns using multiple conditions in R

0

Recipe Objective

How to apply multiple filters on multiple columns using multiple conditions in R? A filter () function is used to filter out specified elements from a dataframe that returns TRUE value for the given condition(s). filter () helps to reduce a huge dataset into small chunks of datasets. **Syntax — filter (data,condition)** This recipe illustrates an example of applying multiple filters.

Step 1 - Import necessary library

install.packages("dplyr") # Install package library(dplyr) # load the package

Step 2 - Create a dataframe

df <- data.frame(student_name = c('U','V','X','Y','Z'), grade = c('AA','CC','DD','AB','BB'), math_marks = c(40,80,38,97,65), eng_marks = c(95,78,36,41,25), sci_marks = c(56,25,36,87,15)) print(df)
"Dataframe is ":
  student_name grade math_marks eng_marks sci_marks
1            U    AA         40        95        56
2            V    CC         80        78        25
3            X    DD         38        36        36
4            Y    AB         97        41        87
5            Z    BB         65        25        15

Step 3 - Apply filter()

Using the & operator (and) for filtering out the required rows print(filter(df,math_marks>40 & eng_marks<75))
"Output of code is ":
  student_name grade math_marks eng_marks sci_marks
1            Y    AB         97        41        87
2            Z    BB         65        25        15
Using the | operator (or) for filtering out the required rows print(filter(df,math_marks>40 | eng_marks<75))
"Output of code is ":
  student_name grade math_marks eng_marks sci_marks
1            V    CC         80        78        25
2            X    DD         38        36        36
3            Y    AB         97        41        87
4            Z    BB         65        25        15

Relevant Projects

Data Science Project in Python on BigMart Sales Prediction
The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

Data Science Project on Wine Quality Prediction in R
In this R data science project, we will explore wine dataset to assess red wine quality. The objective of this data science project is to explore which chemical properties will influence the quality of red wines.

Perform Time series modelling using Facebook Prophet
In this project, we are going to talk about Time Series Forecasting to predict the electricity requirement for a particular house using Prophet.

Data Science Project-TalkingData AdTracking Fraud Detection
Machine Learning Project in R-Detect fraudulent click traffic for mobile app ads using R data science programming language.

Customer Market Basket Analysis using Apriori and Fpgrowth algorithms
In this data science project, you will learn how to perform market basket analysis with the application of Apriori and FP growth algorithms based on the concept of association rule learning.

Machine Learning project for Retail Price Optimization
In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

Identifying Product Bundles from Sales Data Using R Language
In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

Predict Macro Economic Trends using Kaggle Financial Dataset
In this machine learning project, you will uncover the predictive value in an uncertain world by using various artificial intelligence, machine learning, advanced regression and feature transformation techniques.

Predict Employee Computer Access Needs in Python
Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.